【发布时间】:2018-06-24 02:17:12
【问题描述】:
我不确定为什么这段代码没有按预期工作,有人可以帮我吗?
# check if a user eligible for watching coco movie or not.
# if user name starts with "a" or "A" and his age is greater then 10 then he can, else not.
user_name = input("please enter your name in letters here: ")
user_age = int(input("please enter your age in whole numbers here: "))
if user_name[0] == ("a" or "A") and user_age > 10 :
print("you can watch coco movie")
else:
print("sorry, you cannot watch coco")
我在所有可能的条件下测试了这段代码,它工作正常,但最后一个条件没有按预期工作,最后一个条件不知道为什么条件为 False。
我在这里粘贴所有测试条件和 IDLE 的结果:
please enter your name in letters here: a
please enter your age in whole numbers here: 9
sorry, you cannot watch coco
>>>
====================== RESTART: D:\MyPythonScripts\1.py ======================
please enter your name in letters here: a
please enter your age in whole numbers here: 10
sorry, you cannot watch coco
>>>
====================== RESTART: D:\MyPythonScripts\1.py ======================
please enter your name in letters here: a
please enter your age in whole numbers here: 11
you can watch coco movie
>>>
====================== RESTART: D:\MyPythonScripts\1.py ======================
please enter your name in letters here: A
please enter your age in whole numbers here: 9
sorry, you cannot watch coco
>>>
====================== RESTART: D:\MyPythonScripts\1.py ======================
please enter your name in letters here: A
please enter your age in whole numbers here: 10
sorry, you cannot watch coco
>>>
====================== RESTART: D:\MyPythonScripts\1.py ======================
please enter your name in letters here: A
please enter your age in whole numbers here: 11
sorry, you cannot watch coco
>>>
【问题讨论】:
-
@Patrick Haugh。对不起,先生,我的问题不同。
标签: python-3.x