miércoles, 22 de febrero de 2017

Sum of numbers

Sum of numbers
For this task we needed a code that asks for a range of integers and then prints the sum of the numbers in that range (inclusive). You can use a formula to calculate this of course but what we want you to do here is practice using a loop to do repetitive work.

1.- First write the upper and lower bound:

print ("Sum of Nubers")

x=int(input(("Give me the lower bound")))
y=int(input(("Give me the upper bound")))
sum = 0

2.- State the range of the numbers using the "for a in ()" function:
for a in range(x,y+1): this states the number of times you want the sum of numbers to happen
    sum+=a
print ("The sum between the numbers is",sum)

Check out http://www.python-course.eu/python3_for_loop.php for more info and to find some help


#WSQ04

No hay comentarios:

Publicar un comentario