-1

I'm learning Python for about a month and I'm trying to do something easy, but don't know how to continue with this:

age = int(input('Kolik je ti let? '))
if age >= 0 and age <= 17:
  print('You are not old enough to drive a car, sorry.')
if age >= 18 and age <= 200:
  print('You can drive a car.')
  is_licenced = str(input('Wait a minute. there is another important question, do you have driver licence? Say Yes or No: '))
  if is_licenced == 'Yes' or 'yes' or 'YES':
    print('Alright, I trust you, you can drive a car now.')
  if is_licenced == 'NO' or 'No' or 'no':
    print('Use a bike...')

When I write no, it gives me both answers, for YES and for NO, how to separate the output for both answers?

martineau
  • 119,623
  • 25
  • 170
  • 301
  • 1
    This `is_licenced == 'Yes' or 'yes' or 'YES'` doesn't do what you think it does. Type in your Python interpreter: `'Yes' or 'yes' or 'YES'` and execute this. You'll see `'Yes'` as output. Same for the line with `'No'`s. – ForceBru Mar 21 '20 at 19:37
  • If you remove the other "2" options in each `if` statement you will see that the when you enter `Yes` that scope is executed, if `NO` then the other `if` scope will run. It's because you have not explicitly defined the other string inputs thats why it's running both ways. If not write them out clearly or define the options within a list and then check if that option is within the list and return the debug statements... – de_classified Mar 21 '20 at 19:43
  • Also, no need to typecast input as it's already a string for is_licenced. And the proper structure for this would be if elif if elif else else. 3 checks for age and a nested if elif else tocheck for yes or no or a false value. – Arundeep Chohan Mar 21 '20 at 21:11

1 Answers1

0

"yes" and "no" are strings -- they evaluate to true.

Try this:

if is_licenced == 'Yes' or is_licensed== 'yes' or is_licensed=='YES':
    print('Alright, I trust you, you can drive a car now.')
  if is_licenced == 'NO' or is_licensed == 'No' or is_licensed == 'no':
    print('Use a bike...')
nz_21
  • 6,140
  • 7
  • 34
  • 80