Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
For loops index
#1
event = ["A","B","C","D"]


for x in range(4):
 
    maximum=(int(input("Enter the maximum points for the " + event[x]  + " event ")))
    if maximum<5 or maximum>50:
        
        x=x-1
        
        print("The score should be between 5 and 50")
        
        continue
    else:
        print("The maximum points for the " + event[x]  + " event is " ,maximum)
        print("\n----------------------------------------------")
       
        
If a user enter a number less than 5 or more than 50 the code should go back to loop but the index should not be incremented. I tried it but it seems x=x-1 has no effect on the increment of the index. Any idea or suggestion what I am doing wrong or what I can do differently?
Thanks.
Reply


Messages In This Thread
For loops index - by rturus - Mar-23-2021, 08:48 AM
RE: For loops index - by Serafim - Mar-23-2021, 09:29 AM
RE: For loops index - by BashBedlam - Mar-23-2021, 02:51 PM
RE: For loops index - by deanhystad - Mar-23-2021, 03:27 PM
RE: For loops index - by rturus - Mar-23-2021, 03:28 PM
RE: For loops index - by deanhystad - Mar-23-2021, 03:34 PM

Forum Jump:

User Panel Messages

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