You can check if a number is inside a range() if you have a continious range to cover.
Do not convert to int multiple times, store your int value: bAsInt = int(b)
and use that.
If you want to check against specific single values, use a set() if you have 4 or more values - it is faster that a list-lookup:
even = {1300,1302,1304,1306,1308}
for number in range(1299,1311):
# print(number," is 130* :", number//10 == 130 ) # works too, integer division
print(number," is 130* :", number in range(1300,1310),
" and ", "even" if number in even else "odd")
Output:
1299 is 130* : False and odd
1300 is 130* : True and even
1301 is 130* : True and odd
1302 is 130* : True and even
1303 is 130* : True and odd
1304 is 130* : True and even
1305 is 130* : True and odd
1306 is 130* : True and even
1307 is 130* : True and odd
1308 is 130* : True and even
1309 is 130* : True and odd
1310 is 130* : False and odd
Take value from user and compare:
Could be solved like so:
def inputNumber():
# modified from other answer, link see below
while True:
try:
number = int(input("Please enter number: "))
except ValueError:
print("Sorry, I didn't understand that.")
continue
else:
return number
b = inputNumber()
even = {1300,1302,1304,1306,1308}
if b > 1230 and b not in even and b in range(1300,1310):
# r > 1230 is redundant if also b in range(1300,1310)
print("You won the lottery")
It will print smth for 1301,1303,1305,1307,1309 (due to the in even
) .
Other answer: Asking the user for input until they give a valid response