Oct-28-2018, 04:57 AM
Hi, my for loop is not working, i can't figure out how to write the coding for this sum of range of x to y. Thanks.
import statistics print("This program prints the sum of a range of numbers from x to y") print("For example, if x is 10 and y is 50, the program will print the sum of numbers from 10 to 50") x = str(input('Please enter the value of x:' )) y = str(input('Please enter the value of y:' )) if x.isnumeric() and y.isnumeric(): if (int(x) > 0) and (int(y) > 0): if int(y) > int(x): sum_of_numbers = 0 counter = 0 for counter in range(int(x), int(y)): sum_of_numbers += 1 print("The sum of numbers between", x, "and", y, "is", sum_of_numbers) else: print("You did not enter a value of y that is greater than x!") print("Unable to continue. Program terminated.") else: print("One or more of your inputs are not greater than zero") print("Unable to continue. Program terminated.") else: print("One or more of your inputs are not numeric!") print("Unable to continue. Program terminated.")