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.
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")
Comments
Leave a comment