Sorry for the wordy title, but I couldn't think of a better way to phrase it. I am comparing 2 values within an if statement. While I would normally do something like this
val = 1
work = input('1 or 2' )
if work == '1':
#must compare value of val
if val == 1:
print('Val is equal to 1')
elif work == '2':
if val == 2:
print('val is equal to 2 ')
#also also compare value of val
All the tutorials say that nesting ifs is a bad practice and will come back to bite you. Is there a better way to do this?
Aucun commentaire:
Enregistrer un commentaire