+ 2
how to solve this problem? choose 0 or 2 or 4 to see problem đđđ{ SOLVED }
4 Respostas
+ 5
Just break the loop after conditions,then it will work fine!
https://code.sololearn.com/c892FM9Ffb1V/?ref=app
+ 6
instead of using:
if tickets[choose]%2 != 0:
....
you could use the membership operator "in":
if choose in tickets:
...
When using code like you did, and user selects a number that is not in list, you get an index error and program gets terminated.
+ 5
Hassan ăă Raage , i forgot something to mention:
I assume that you want all odd numbers to make for free, and all even numbers to pay for. In this case you can go an other way:
- insted of using a list, you may use a range defined like below: This range has a definition running from 1 (first odd number) up to 9 (but as 9 is not included you take 10), and use a step from number to number of 2.
Can you try and give a short feedback if it meets your requirements? When you need to have numbers greater than defined, just modify the second number to your requirements.
choose = int(input("Choose item number : "))
while True:
if choose in range(1,10,2):
print("Free item")
break
else:
print("Price $")
break
+ 3
Lothar Thanks i've change if tickets[choose] to if choose in tickets, thanks a lot