我可以说"如果你的var1 =是和var2 =是"然后做点什么?

时间:2018-02-07 13:09:55

标签: 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" :

1 个答案:

答案 0 :(得分:0)

是的,您可以使用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,因为在"A"作为答案后,其他内容不会被执行。 (may read this

  

此外,正如Chris_Rands建议的那样,在这种情况下,您可以使用以下内容简化if语句:if architect == computerProgramer == "Yes": ...