Q. Write a program that repeatedly asks from users some numbers until string 'done' is typed. The program should print the sum of all numbers entered.


Answer :-


total = 0
s = input('Enter a number or "done": ')
while s != 'done' :
    num= int(s)
    total = total + num
    s = input('Enter a number or "done": ')
print('The sum of entered numbers is ', total)


Output :-

Enter a number or "done": 1
Enter a number or "done": 2
Enter a number or "done": 3
Enter a number or "done": 4
Enter a number or "done": done
The sum of entered numbers is  10
>>>

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post