How to have user true/false input in python?

前端 未结 7 596
野的像风
野的像风 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 11:57

    You could just try bool(input("...")) but you would get into trouble if the user doesn't input a bool. You could just wrap it in a try statement.

提交回复
热议问题