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
Post a Comment