我能说“如果你的var1=yes和var2=yes”然后做点什么吗?

2024-05-15 11:01:09 发布

您现在位置:Python中文网/ 问答频道 /正文

下面的程序应该有助于通过一些嵌套的if-语句来预测您未来的工作。你知道吗

print("This app will predict which job suits you best")
ComputerProgramer = input("Are you good at coding. A)Yes. B)No. [A/B]")
if ComputerProgramer == "A":
    ComputerProgramer = "Yes"
else :
    ComputerProgramer = "No"

Architect = input("Are you good at drawing. A)Yes. B)No. [A/B]")
if Architect == "A":
    Architect = "Yes"
elif Architect == "Yes", ComputerProgramer == "Yes"  :
    FinalAnswer = input("which one do you prefer? A)coding. B)drawing. [A/B]")
    if FinalAnswer == "A":
        print("Computer Programer")
    else :
        print("Architect")
else :
    Architict = "no"

你能帮我找一个替代品吗 elif Architect == "Yes", ComputerProgramer == "Yes" :?你知道吗


Tags: noyouwhichinputifelseareat
1条回答
网友
1楼 · 发布于 2024-05-15 11:01:09

是的,您可以使用and。您的代码可以如下所示:

computerProgramer = input("Are you good at coding. A)Yes. B)No [A/B]")
if computerProgramer == "A":
    computerProgramer = "Yes"

architect = input("Are you good at drawing. A)Yes . B)no. [A/B]")
if architect == "A":
    architect = "Yes"

if (architect == "Yes") and (computerProgramer == "Yes")  :
    finalAnswer = input("which one do you prefer? A)coding B)drawing [A/B]")
    if FinalAnswer == "A":
        print("Computer Programer")
    else :
        print("Architect")

注意:我把你的elif改成了一个新的if,因为else不会在"A"之后被排除。(may read this

Furthermore, as Chris_Rands suggested, in this case you can simplify the if-statement with: if architect == computerProgramer == "Yes": ...

相关问题 更多 >