Ask the user for two positive numbers and add them together. If the answer is 50 or more then display the answer in a user friendly format. If the answer is below 50, ask the user to continue to select more numbers until the answer is 50 or above.
sum = 0
while sum <=50:
val1 = int(raw_input("Enter the first number: "))
val2 = int(raw_input("Enter the second number:"))
sum = val1+val2
if sum >= 50:
print "The sum is: "+sum
Use the above code. Hope it works. But this is an infinite loop, until the sum becomes 50.
please try this
sum=0;
while sum <= 50:
num1=input("enter first value ");
num1=float(num1);
num2=input("enter second value ");
num2=float(num2);
sum=num1+num2;
print("sum of ",num1," and ",num2," is ",sum);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.