【发布时间】:2021-10-12 05:06:51
【问题描述】:
所以最近我刚刚使用 if else 语句进行了一项调查,并遇到了我的条件未完全满足的问题。起初,我的代码似乎运行良好,但后来我意识到,在某些输入下,代码会崩溃或响应不同的条件。
我最大的问题是,当我在(2 到 10)中输入任何内容时,它指的是只有在输入大于 18 时才可能出现的条件......但是数字(10 到 17)在什么情况下工作得很好我需要
同样,对于任何 100 及以上的数字,它都不是指 >18 代码,而是指小于
我觉得我错过了什么,这是下面的代码,请帮助
print("Welcome user, today we will be evaluating if you need to sign up for selective service or not.\n"
"DO NOT LIE!")
print("")
name = input("Please enter your name: ")
age = input("Please enter your age: ")
Male = "M".casefold()
Female = "F".casefold()
gender = input("Please enter an (M or F) for gender identity: ").casefold()
if age >= str(18) and gender == Male:
print("Welcome {}, since you are a Male that is 18 or over please sign where directed for selective service".format(name))
input("Name and DOB: ")
print("You will get a letter/email if your service is ever required.")
if age < str(18)) and gender == Male:
print("You are not required to signup for selective service yet {}, please return in {} years.".format(name, 18-int(age)))
else:
if gender == Female:
print("You do not meet the criteria to sign up, have a good day!")
【问题讨论】:
标签: if-statement python-3.9 multiple-conditions