Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python告诉我66<;=17_Python_Python 3.x - Fatal编程技术网

Python告诉我66<;=17

Python告诉我66<;=17,python,python-3.x,Python,Python 3.x,我是python新手,尝试构建一个程序来评估潜在的合作伙伴对于使用/2+7规则的人来说是否太年轻 尽管使用的测试变量远远高于18,但无论我做什么,程序都会执行第7行。我使用了88/77、77/66、19/19,它总是执行第7行 num1 = float(input("What is the higher age number? ")) num2 = float(input("What is the lower age number? ")) output = num1 / 2 + 7 if nu

我是python新手,尝试构建一个程序来评估潜在的合作伙伴对于使用/2+7规则的人来说是否太年轻

尽管使用的测试变量远远高于18,但无论我做什么,程序都会执行第7行。我使用了88/77、77/66、19/19,它总是执行第7行

num1 = float(input("What is the higher age number? "))
num2 = float(input("What is the lower age number? "))
output = num1 / 2 + 7
if num1 and num2 <= 17:
    print("You're both underage")
elif num2 <= 17:
    print("You're going to jail bud")
elif output <= num2:
    print("That's OK")
else:
    print("They are slightly too young for you")
num1=float(输入(“更高的年龄数字是多少?”)
num2=浮动(输入(“较低的年龄数字是多少?”)
输出=num1/2+7
如果num1和num2表达式:

if num1 and num2 <= 17:
从python文档:


问题是针对这一行代码:

if num1 and num2 <= 17:

如果num1和num2写
num1和num2,我不知道第7行是什么,但是
如果num1和num2仍然存在这个问题@Brandon?因为代码适用于您打印的所有测试用例,所以我只是测试了它。我是个白痴,我在终端中运行了错误的.py文件--哈哈,这在我身上发生了无数次…@Brandon,如果下面的解决方案解决了您的问题,请接受它(勾选左侧)。您也可以投票支持您认为有用的任何其他解决方案。
if num1 == True and num2 <= 17:
if num1 <= 17 and num2 <= 17:
if num1 and num2 <= 17:
if num1 <= 17 and num2 <= 17
if all(i <= 17 for i in [num1,num2]) 
if num1 <= 17 and num2 <= 17:
    # do something
if max(num1, num2) <= 17:
    # do something