Python Forum
python homework print the sum of a range of numbers from x to y
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python homework print the sum of a range of numbers from x to y
#1
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.")
Reply


Messages In This Thread
python homework print the sum of a range of numbers from x to y - by kirito85 - Oct-28-2018, 04:57 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Random Generator: From Word to Numbers, from Numbers to n possibles Words Yamiyozx 2 1,454 Jan-02-2023, 05:08 PM
Last Post: deanhystad
  HELP in python homework makashito 4 3,951 Oct-12-2021, 10:12 AM
Last Post: buran
  CyperSecurity Using Python HomeWork ward1995 1 1,981 Jul-08-2021, 03:55 PM
Last Post: buran
Exclamation urgent , Python homework alm 2 2,332 May-09-2021, 11:19 AM
Last Post: Yoriz
  Convert list of numbers to string of numbers kam_uk 5 3,054 Nov-21-2020, 03:10 PM
Last Post: deanhystad
  Homework with python Johnsonmfw 1 1,702 Sep-20-2020, 04:03 AM
Last Post: ndc85430
  Python Homework Help *Urgent GS31 2 2,611 Nov-24-2019, 01:41 PM
Last Post: ichabod801
  Scaling random numbers within specific range schniefen 4 3,208 Oct-28-2019, 11:22 AM
Last Post: jefsummers
  How to Generate and Print An Array with Random Numbers in Python in the johnnynitro99293 14 9,681 Sep-20-2019, 11:56 AM
Last Post: ichabod801
  Python Homework Question OrcDroid123 1 2,392 Sep-01-2019, 08:44 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020