Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
For \ While loops
#1
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
Reply


Messages In This Thread
For \ While loops - by Itay - Oct-31-2018, 02:23 PM
RE: For \ While loops - by j.crater - Oct-31-2018, 02:30 PM
RE: For \ While loops - by Itay - Oct-31-2018, 02:34 PM
RE: For \ While loops - by j.crater - Oct-31-2018, 02:38 PM
RE: For \ While loops - by Itay - Oct-31-2018, 02:49 PM
RE: For \ While loops - by j.crater - Oct-31-2018, 03:01 PM
RE: For \ While loops - by Itay - Oct-31-2018, 03:17 PM
RE: For \ While loops - by ichabod801 - Oct-31-2018, 03:20 PM
RE: For \ While loops - by Itay - Oct-31-2018, 03:27 PM
RE: For \ While loops - by ichabod801 - Oct-31-2018, 07:58 PM

Forum Jump:

User Panel Messages

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