In: Computer Science
Test Case:
Enter float: 1.0
Enter float: 0.5
Enter float: A
Error: that is not a number
Enter float: B
Error: that is not a number
The sum of the numbers is 1.5
Python, keep it simple, thank you
Python code:
#initializing total as 0
total=0
try:
#looping till an invalid number is entered
while(True):
#accepting number
num=float(input("Enter
float: "))
#adding it to
total
total+=num
except:
#printing Error
print("Error: that is not a number")
try:
#looping till an invalid
number is entered
while(True):
#accepting number
num=float(input("Enter float: "))
#adding it to total
total+=num
except:
#printing Error
print("Error: that is
not a number")
#printing total
print("The sum of the numbers is",total)
Screenshot:
Input and Output: