Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python的DEF()语句中使用if返回错误的值_Python_Python 3.x - Fatal编程技术网

在python的DEF()语句中使用if返回错误的值

在python的DEF()语句中使用if返回错误的值,python,python-3.x,Python,Python 3.x,我最近开始使用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

我最近开始使用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筹码,你想下什么赌注?十,

第一个骰子是。。。六,

第二个骰子是1

所以你的号码是7

扔掉!减10个筹码


再来一次?Y/N

如果RESULTHAZARD为2,
RESULTHAZARD==2或3
计算结果为
True或3
计算结果为
True
。否则,
RESULTHAZARD==2或3
计算结果为
False,或3
计算结果为
3
,这是一个真实值

您需要显式比较两者是否相等。使用
RESULTHAZARD==2或RESULTHAZARD==3
,或在(2,3)中使用
RESULTHAZARD


对于
=
运算符,可以使用与
相关的多个检查,也可以将
不在
中与感兴趣的值序列一起使用。

对于!=陈述