i am trying to print a message after the user inputs a 0 but nothing is outputted, the same goes for entering 200, and that seems to work fine except the 0.
i have tried putting and/or and nothing.
im just learning python from last week, so i am a beginner
thanks in advance
highway_num = int(input())
if 0 < highway_num < 100:
print(f'I-{highway_num} is primary,', end='')
if highway_num % 2 == 0:
print(' going east/west.')
else:
print(' going north/south.')
if 99 < highway_num < 1000:
if highway_num == 0 or highway_num == 200:
print(f'{highway_num} is not a valid interstate highway number.')
else:
print(f'I-{highway_num} is auxiliary,', end='')
CodePudding user response:
Helo steph! I added some comments in you code bellow. Please, check if it's good enough for you.
highway_num = int(input())
# Numbers from 1 to 99
if 0 < highway_num < 100:
print(f'I-{highway_num} is primary,', end='')
if highway_num % 2 == 0:
print(' going east/west.')
else:
print(' going north/south.')
# Numbers from 100 to 999
# I changed your IF for an ELIF statement.
elif 99 < highway_num < 1000:
# Value 0 is impossible here! :) since this block is only executed if the number is between 100 and 999.
if highway_num == 0 or highway_num == 200:
print(f'{highway_num} is not a valid interstate highway number.')
else:
print(f'I-{highway_num} is auxiliary,', end=' ')
print('sorry.') # Added so the console message is printed.
# This ELSE is any not valid number.
else:
print(f'{highway_num} is not valid. Try a number from 1 to 999')