Tag Archives: #WSQ07

#WSQ07

#WSQ07, sum of numbers

#WSQ07
in this program i use a while to make the sum of number in a range, need to make a counter, the counter helpme to do that the program finished whit counter get some value.
here is the link: https://github.com/juanheuforico/mastery/blob/master/sumof.py
here is

print(“give me  a range of integers to prints the sum of the numbers in that range “)
r1=int(input(“value to star “))
r2=int(input(“value to finish “))
cont= r1
acum=r1
while cont<r2:
    cont=cont+1
    acum=acum+1
    r1=r1+acum
    print(r1)

#WSQ07, sum of numbers

#WSQ07, sum of numbers

#WSQ07
in this program i use a while to make the sum of number in a range, need to make a counter, the counter helpme to do that the program finished whit counter get some value.
here is the link: https://github.com/juanheuforico/mastery/blob/master/sumof.py
here is

print(“give me  a range of integers to prints the sum of the numbers in that range “)
r1=int(input(“value to star “))
r2=int(input(“value to finish “))
cont= r1
acum=r1
while cont<r2:
    cont=cont+1
    acum=acum+1
    r1=r1+acum
    print(r1)

#WSQ07, sum of numbers

Sum of numbers

Aqui lo que hice fue usar un do while para que se repita el ciclo mientras los numeros sean acomodados correctamente primero el menor y luego el mayor.

Busqué ayuda con un compañero para que me explicara el ciclo for.

 

 

Aquí está mi codigo: https://github.com/fernandoaguirrer/TC1017/blob/master/WSQ07.md

 

 

#WSQ07 #TC1017

Sum of numbers

There is my code

 

Sum of Numbers #WSQ07

I just used a variable with the initial value as the lower bound, and had it to count the loops and sum that into the final sum every loop, until the counting variable was the same value as the upper bound. 

Here’s my code:

https://www.dropbox.com/s/r1pqsoqn7exuura/sum.py?dl=0

Oscar Ricardo López López A01229116

WSQ07 – sum of numbers

the program has to sum all the integers in range between two numbers given by the user. at first I did it with the range function but the teacher asked for a loop to make the operation so I did it like this.

ask for two integers, one low and one high but if the user enters the a lower number in the high number place the program wont work properly so I added a condition to correct the numbers:

x = low

y = high

if x > y:

    x,y = y,x

that will exchange the values between the x and y and so continue the program correctly. now to do the sum i added a variable with a value of 0 and used a while loop:

z = 0

while x != y:

   z = z+x

   x += 1

that will add x to z and rise x one number to keep the loop until x=y but will stop before the last number, if x=1 and y=5 then the operation would be 1+2+3+4 excluding the high number, to fix this I added a last operation at the end to print the sum the resulting z with the high number y:

print (z+y)

and it’s done.

question – how do I tell the program to ask again for an integer if the user enters a string?

my code in github:

https://github.com/nazare52/progra/blob/master/wsq07.py

 

Wsq07

Sum Of Numbers


Example Run: 
We will calculate in the range you provide.
Please give us the lower bound:  1
Please give us the upper bound: 10
The sum from 1 to 10 (inclusive) is: 55
Dropbox link to my code:
https://www.dropbox.com/s/1k5dobdb2gg1cmz/Wsq07.py?dl=0

Wsq07

Sum Of Numbers


Example Run: 
We will calculate in the range you provide.
Please give us the lower bound:  1
Please give us the upper bound: 10
The sum from 1 to 10 (inclusive) is: 55
Dropbox link to my code:
https://www.dropbox.com/s/1k5dobdb2gg1cmz/Wsq07.py?dl=0