我最近开始使用python 3.0,并编写了一个危险赌场游戏,我使用的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个
第一个骰子是。。。六
第二个骰子是1
所以你的号码是7
扔出去!零下10个筹码
再来一次?是/否
如果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
与感兴趣的值序列一起使用相关问题 更多 >
编程相关推荐