Python 带有两个不同变量的if命令

Python 带有两个不同变量的if命令,python,Python,我有一个用户输入,然后是一个if语句,但是在这个if语句中我想检查两个不同的变量?不管我怎么努力,它都不起作用 if hm == 3 and karma == 8: print ("hello whatever") 这是我已经尝试过的,但它是错误的,那么我用什么来检查两个不同的变量呢,谢谢 编辑:所以我只是在做一个小游戏。。。这是到目前为止我的代码 发生的情况是,当它到达问题区域时,它只是跳转到结束消息 import time x = 1 karma = 0 money = 50 ti

我有一个用户输入,然后是一个if语句,但是在这个if语句中我想检查两个不同的变量?不管我怎么努力,它都不起作用

if hm == 3 and karma == 8:
    print ("hello whatever")
这是我已经尝试过的,但它是错误的,那么我用什么来检查两个不同的变量呢,谢谢

编辑:所以我只是在做一个小游戏。。。这是到目前为止我的代码

发生的情况是,当它到达问题区域时,它只是跳转到结束消息

import time
x = 1
karma = 0
money = 50
ticket1 = 1





name = input("what is your name")
print ("hello", name)

time.sleep(1.5)

check = input("would you like to start your adventure")

if check == "yes" or "Yes" or "yeah":
    print ("good then lets get going")

else:
    print ("bye loser")
    SystemExit

time.sleep(1.5)


print ("you are walking down a road on the way to the shops, when all of a sudden a homeless man asks you for some change")
time.sleep(1)
hm = input("do you 1. give the man all your money, 2. give him some small change, 3. tell him to eff off")

if hm == "1":
    print("you gave the man all your money, karma + 10, you have no money now")
    money = 0
    karma = 10
    x = 1

if hm == "2":
    print ("you give him $10, karma + 2, you have $40 left")
    money = 40
    karma = 2
    x = 1

if hm == "3":
    print (" you tell the man to fuck off, he looks hungry and disappointed, turns out he died later that day. karma - 5, you have $50 left")
    money = 50
    karma = -5
    x = 2

print(".")
print(".")
print(".")
print(".")



time.sleep(1.5)

print ("a bit further down the road you pass a street salesman selling golden tickets,")
time.sleep(1.5)
print("he say's .. they will be worth it later on in the game , honestly..")
time.sleep(1.5)
check1 = input("do you 1. buy a ticket ($5) 2. don't buy a ticket 3. threaten to punch him unless he gives you a ticket")
time.sleep(1)

if hm == 3 and karma == -5:
    money + 5
    print("you beat the shit out of him and take a golden ticket as well as $5, karma -5, you have", money, "dollars left")
    karma = -10
    ticket1 + 1

if hm== 3:
    print ("he cowers under your influence and gives you a ticket you have ", money, "dollars left, karma - 5")
    karma -5
    ticket1 + 1

if hm == 2:
    print ("you walk on withought buying a ticket, no change in karma, you have ", money, " dollars left")

if hm == 1:
    money -10
    ticket1 +1
    print("you buy a golden ticket, you have ", money, " left")

print("well thats all folks")

看起来正确,但缺少冒号:

if hm == 3 and karma == 8:
    print ("hello whatever")

你应该检查hm和karma变量是否包含整数。最简单的方法可能是在if之前添加以下行:


如果输出是这样的,那么您需要将字符串转换为整数,或者只与字符串进行比较:hm='3'。

错误地说,您的意思是money和ticket1不会更新吗?你有

if hm == 3 and karma == -5:
   money + 5
   print("you beat the shit out of him and take a golden ticket as well as $5, karma -5, you have", money, "dollars left")
   karma = -10
   ticket1 + 1
但是我猜你想更新money和ticket1的值,所以你不想用money+5,而是想这样加上5:money+=5。在前一种情况下没有赋值,只有一个打印,如果您在控制台中执行,但在后一种情况下有。ticket1也是如此,也许还有因果报应?该守则将成为:

if hm == 3 and karma == -5:
   money += 5
   print("you beat the shit out of him and take a golden ticket as well as $5, karma -5, you have", money, "dollars left")
   karma = -10
   ticket1 += 1
如果有问题:

if check == "yes" or "Yes" or "yeah":
    print ("good then lets get going")

else:
    print ("bye loser")
    SystemExit
收费至:

if check.lower() == "yes" or check.lower() == "yeah":
    print ("good then lets get going")
else:
    print ("bye loser")
    sys.exit()
系统需求

import sys

你在if行的末尾缺少了一个:对我来说似乎是对的,除了你在if语句的末尾缺少了一个“:”。到底什么不起作用?hm和业力的价值观是什么?他们来自哪里?提示:a:necessaray在if行的末尾。什么不起作用?你有错误吗?如果是,什么?3!=3.请确保在使用之前将用户输入转换为正确的类型。很抱歉,我错过了这一点。。在这种情况下,我确实有一个冒号,条件是正确的,它不起作用的原因是因为它返回false,即hm!=还是因果报应!=8.或者更好,如果勾选。低一点是的,是的:
import sys