How to have user true/false input in python?

前端 未结 7 519
野的像风
野的像风 2021-01-19 11:00

I\'m new to python.

I want the program to ask

\"is Johnny hungry? True or false?\"

user inputs True then print is

相关标签:
7条回答
  • 2021-01-19 12:00

    Code:

    question = str(input("Is Johnny hungry?  Response: "))
    
    if question == "yes":
    
        print("Johnny needs to eat food!")
    
    if question == "no":
    
        print("Johnny is full!")
    

    Run:

    1. Is Johnny hungry? Response: yes

      Johnny needs to eat food!

    2. Is Johnny hungry? Response: no

      Johnny is full!

    3. This is if you type something other than yes and no

      Is Johnny hungry? Response: lkjdahkjehlhd

    Nothing pops up/ there is no response

    0 讨论(0)
提交回复
热议问题