loops - End a program after meeting user entered sum in Python -



loops - End a program after meeting user entered sum in Python -

total = 0 not_total = true sum_of_square = int(input("enter desired sum: ")) while (not_total == true): n in range (2): total = total + n**2 print("the sum of squares 1^2 {0}^2 equal {1}.".format(n,total))

this provide infinite amount of sums want stop total sum before user input

you can compare 2 values in conditional statement of while loop so:

total = 0 sum_of_square = int(input("enter desired sum: ")) while (sum_of_squares <= total): n in range (2): total = total + n**2 print("the sum of squares 1^2 {0}^2 equal {1}.".format(n,total))

python loops while-loop sum

Comments

Popular posts from this blog

maven fortify plugin : Unable to load build session with ID XXXXX .. See log file for more details -

c# - Primavera WebServices does not return any data -

android - Display emoji panel with genymotion - keyboard/touch input? -