+ 1
Help needed with Python 3
Hello everyone, I need some assistance with code running. It should be very easy, but I encountered some difficulties as I am a beginner in Python. How to print integers from input using while loop? Letâs say, you enter multiple numbers and want python to print all numbers vertically and then total amount below that. Thank you
2 Answers
+ 3
a=1 #give a valid value to a
tot=[] #create list to hold input values
while a!=0: #a is 1 so it runs
a= int(input()) #until user inputs 0
if a!=0:tot.append(a) #put vals in list
print(*tot,sep='+',end='=')
print(sum(tot))
'''in sololearn, put enter between values, last one must be a 0(zero)'''
+ 1
Louis is correct and informative. Here is his post cleaned up a bit to help explain
a=1
#give a positive value to a to
#start the loop
tot=[]
#create a list to hold input values
#as long as a is not 0 the loop
#will run
while a!=0:
#each run gets input
a= int(input())
#if the input is 0 it ends the
#loop. Other than 0, it stores
#it to the list if it
if a!=0:tot.append(a)
#Then simply print the results
print(*tot,sep='+',end='=')
print(sum(tot))
'''in sololearn, put enter between values, last one must be a 0(zero)'''