#WSQ07<\/a> #TC1014<\/a> #awesome<\/a><\/strong><\/p>\n 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.<\/strong><\/p>\n 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:<\/strong><\/p>\n x = low<\/strong><\/p>\n y = high<\/strong><\/p>\n if x > y:<\/strong><\/p>\n x,y = y,x<\/strong><\/p>\n 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:<\/strong><\/p>\n z = 0<\/strong><\/p>\n while x != y:<\/strong><\/p>\n z = z+x<\/strong><\/p>\n x += 1<\/strong><\/p>\n 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:<\/strong><\/p>\n print (z+y)<\/strong><\/p>\n and it’s done.<\/strong><\/p>\n question – how do I tell the program to ask again for an integer if the user enters a string?<\/strong><\/p>\n my code in github:<\/strong><\/p>\n https:\/ <\/strong><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":" #WSQ07 #TC1014 #awesomethe 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 i… Continue reading