我最近开始使用python 3.0,并且已经编写了一个Hazard赌场游戏,我正在使用这样的if语句:
def starthazard():
global chips
Main = input ("Main")
time.sleep(0.1)
if Main == "?" :
print(" Hazard Rules... ")
time.sleep(0.5)
print("You can main 6,7,8 or 9. The main your luckiest number")
time.sleep(0.5)
print("Nicks is winning either 3 / 1 if main is rolled but 1 / 2 if chance is rolled.")
print("Rolling your main is nicks")
print("2 or 3 is thrown out")
time.sleep(0.5)
print("with a main of 5 or 9, you throw out with both an 11 and a 12")
print("with a main of 6 or 8, you throw out with an 11 but nick with a 12")
print("with a main of 7, you nick with an 11 but throw out with a 12")
print("Other numbers are Chance, Roll again but this time main is out and Chance is nicks")
time.sleep(6.9)
Main = input ("Main")
Bet = input("you have " + str (chips) + " chips, what bet would you like to
place?")
dice1HAZARD = random.randint(1,6)
dice2HAZARD = random.randint(1,6)
RESULTHAZARD = dice2HAZARD + dice1HAZARD
print("first dice is... " + str (dice1HAZARD))
time.sleep(1)
print("second dice is " + str (dice2HAZARD))
time.sleep(1)
print("therefore your number is "+ str (RESULTHAZARD))
time.sleep(1)
if RESULTHAZARD == 2 or 3 :
print("THROWN OUT! MINUS " + Bet + " Chips" )
chips = chips - int (Bet)
PLAYAGAIN = input("play again? Y/N")
if PLAYAGAIN == "Y":
starthazard()
else:
PICKGAME()
if RESULTHAZARD == Main :
print("NICKS 3/1!")
CHIPSWON = Bet * 3
chips = chips + CHIPSWON
PLAYAGAIN = input("play again? Y/N")
if PLAYAGAIN == "Y":
starthazard()
else:
starthazard()
def CHANCECHECK():
if RESULTHAZARD != Main or 2 or 3 or 11 or 12:
print("CHANCE" + str (RESULTHAZARD) )
dice1HAZARD = random.randint(1,6)
dice2HAZARD = random.randint(1,6)
RESULTHAZARD = dice2HAZARD + dice1HAZARD
print("first dice is... " + str (dice1HAZARD))
time.sleep(1)
print("second dice is " + str (dice2HAZARD))
time.sleep(1)
print("therefore your number is "+ str (RESULTHAZARD))
time.sleep(1)
CHANCECHECK()
为什么会这样返回: 主7
你有800个筹码,你想下注什么? 10第一个骰子是... 6
第二个骰子是1
因此你的号码是7
出来!减去10个筹码
再玩一次?是/否答案 0 :(得分:1)
如果RESULTHAZARD为2,则RESULTHAZARD == 2 or 3
评估为True or 3
,其评估为True
。否则,RESULTHAZARD == 2 or 3
会评估为False or 3
,其评估为3
,这是一个真正的价值。
您需要明确地比较两者的相等性。使用RESULTHAZARD == 2 or RESULTHAZARD == 3
或RESULTHAZARD in (2, 3)
。
对于!=
运算符,可以使用and
连接多个检查,也可以使用感兴趣的值序列使用not in
。