【问题标题】:Creating a program that tells you whether or not you need an umbrella when you leave the house. Not receiving output, but receiving a exit code 0创建一个程序,告诉您离开家时是否需要雨伞。没有收到输出,但收到退出代码 0
【发布时间】:2022-06-14 22:41:17
【问题描述】:

我正在尝试创建一个程序,它最终会告诉您是否需要雨伞(一个非常简单的程序),我只需要一个是/否输出。但是,这是我使用的代码,我根本没有得到输出。我只收到退出代码 0,我需要如何修复它才能收到输出以及退出代码 0?

感谢您的帮助。新手来了。

 weather = input('Is it raining today? option Yes/No')
if weather == 'Yes':
      print('Bring an umbrella')
  if weather == 'No':
   print('No umbrella needed')

【问题讨论】:

    标签: python syntax


    【解决方案1】:

    修复缩进并使用elif:

    weather = input('Is it raining today? option Yes/No')
    if weather == 'Yes':
        print('Bring an umbrella')
    elif weather == 'No':
        print('No umbrella needed')
    else:
        print('Type: Yes or No')
    
    

    【讨论】:

      猜你喜欢
      • 2022-06-14
      • 1970-01-01
      • 2016-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-03
      相关资源
      最近更新 更多