Answer to Question #203575 in Electrical Engineering for sarah

Question #203575

Write a python programme to take two inputs of two different numbers (float) from the user pointed at

by two variables x and y respectively.

 Add the numbers and have the result in the variable z.

 Print the text “The total of two numbers is” concatenated with the sum of the numbers “z” after

changing it by ‘str’ into string form.


1
Expert's answer
2021-06-07T05:47:03-0400
import math
x,y=-1,-1
while(x<0):
    x=int(input("Please enter the first positive number: "))
while(True):
    y=int(input("Please enter the second and different positive number: "))
    if (y>0 and y!=x):
        break
temp_sum_squared=x**2+y**2
temp_diff_squared=x**2-y**2
if temp_diff_squared<0:
    temp_diff_squared=-1*(temp_diff_squared)
temp_sum=math.sqrt(temp_sum_squared)
z_sum=int(temp_sum)
temp_diff=math.sqrt(temp_diff_squared)
z_diff=int(temp_diff)
if z_sum==temp_sum:
    print("These two numbers can form a triplet with",temp_sum)
elif z_diff==temp_diff:
    print("These two numbers can form a triplet with",temp_diff)
else:
    print("These two numbers cannot form a triplet with any positive integer")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS