我如何从if中获得单独的答案-是或否?

时间:2020-03-21 19:35:42

标签: python

我正在学习Python大约一个月,并且试图做一些简单的事情,但是不知道如何继续进行下去:

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...')

当我写否时,它会给我两个答案,对于是和否,如何将两个答案的输出分开?

1 个答案:

答案 0 :(得分:0)

“是”和“否”是字符串-它们的值为true。

尝试一下:

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...')