Oct-31-2018, 02:23 PM
Hello , I'm a python beginner and I need help with For & While loops
1)Ive been asked to code a loop with 'While'. In the loop I need to have 3 variables which in two of them I need to enter different numbers , the loop needs to show me all the numbers between the 2 numbers I have entered including them. Ive managed to do it but only with 2 variables
num1= int(raw_input("Enter a number:"))
num2= int(raw_input("Enter a number:"))
while num1 <= num2:
(space) print num1
(space) num1 += 1
2) Same question as question 1 but now I need to use the Loop 'For' and use 'xrange'. Ive only managed to use 2 variables and I always get the last number -1
num1= int(raw_input("Enter a number:"))
num2= int(raw_input("Enter a number:"))
for num1 in xrange (num1,num2):
(space) print num1
1)Ive been asked to code a loop with 'While'. In the loop I need to have 3 variables which in two of them I need to enter different numbers , the loop needs to show me all the numbers between the 2 numbers I have entered including them. Ive managed to do it but only with 2 variables
num1= int(raw_input("Enter a number:"))
num2= int(raw_input("Enter a number:"))
while num1 <= num2:
(space) print num1
(space) num1 += 1
2) Same question as question 1 but now I need to use the Loop 'For' and use 'xrange'. Ive only managed to use 2 variables and I always get the last number -1
num1= int(raw_input("Enter a number:"))
num2= int(raw_input("Enter a number:"))
for num1 in xrange (num1,num2):
(space) print num1