Issue
Can someone help me pls? i need to write a program that reads numbers entered and then return the total without using 'for' or 'while' and i have no idea how to do it:(
n = 0
count = 0 # `enter code here`
user = input('Enter Numbers:\n> ')
while user != 'done':
try:
n = n + float(user)
except:
print('Enter Numbers or "done"')
user = input('> ')
count = count + 1
if user == 'done':
print('Total:',n)
# this works for me but i need to do it without using loops like 'for' or 'while' :(
Solution
numbers = []
def loop():
n = input('Enter Numbers or done:\n>')
if n == 'done':
print('Total:', sum(numbers))
else:
numbers.append(int(n))
loop()
loop()
Answered By - AspiraDev
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.