Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.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/16.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计算变得很奇怪_Python_Python 3.x - Fatal编程技术网

python计算变得很奇怪

python计算变得很奇怪,python,python-3.x,Python,Python 3.x,我的代码有一些问题。我需要在最大值变化的情况下将输入限制为5的倍数 用我现在拥有的,它应该可以工作,但它不是。我错过了什么 while True: print("Place your bet. Must be a multiple of 5") posBets = range(5, (balance + 1), 5) bet = str(input()) if bet == posBets: print("Y

我的代码有一些问题。我需要在最大值变化的情况下将输入限制为5的倍数

用我现在拥有的,它应该可以工作,但它不是。我错过了什么

while True:
        print("Place your bet. Must be a multiple of 5")
        posBets = range(5, (balance + 1), 5)
        bet = str(input())
        if bet == posBets:
            print("You have bet $" + str(bet))
            loop = 0
        elif bet != posBets:
                print("Please bet an amount that is a multiple of 5, or an amount that is within your balance")
                print("Press enter to continue")
                input()
                loop = 1
        if not(loop == 1):break #Exit loop
循环也有一个问题。当我尝试获取新值时,它需要从原始值中减去并将其发送回main函数,但它总是将其相加,然后不更改发送给main函数的值

win = 1
lose = 2
tie = 3
r = win or lose or tie
print("Battle shall now commence")
print("Choose an attack")
print("The attacks you can use are as follows")
print("(1)Fury Punch")
print("(2)Punishment kick")
print("(3)Sword of justice")
print("(4)Shuriken of Vengence")
print("(5)Numchucks of Anger")
print("(6)Knife of Freedom")
attack = int(input())
while attack < 1 or attack > 6:
    print("please input either: 1, 2, 3, 4, 5 or 6")
    attack = int(input())
winLose(attack, win, lose, tie,)
if r == win:
    newBalance = int(balance) + int(bet)
elif r == lose:
    newBalance = int(balance) - int(bet)
else:
    if r == tie:
        balance = newBalance 
print("Your Balance is $" + str(newBalance))
return(bet, newBalance)
win=1
损失=2
平局=3
r=赢或输或平局
打印(“战斗现在开始”)
打印(“选择攻击”)
打印(“您可以使用的攻击如下”)
打印(“(1)愤怒冲孔”)
打印(“(2)惩罚)
印刷品(“(3)正义之剑”)
印刷品(“(4)Vengence的Shuriken)
印刷品(“(5)愤怒的Numchucks”)
印刷品(“(6)自由之刀”)
攻击=int(输入())
攻击<1或攻击>6时:
打印(“请输入:1、2、3、4、5或6”)
攻击=int(输入())
输赢(进攻,赢,输,平局)
如果r==赢:
新余额=整数(余额)+整数(下注)
elif r==丢失:
新余额=整数(余额)-整数(下注)
其他:
如果r==平局:
平衡=新平衡
打印(“您的余额为$”+str(新余额))
回报(下注、新平衡)
这是完整的代码 谢谢你的帮助

def attack1(pcMove, win, tie, lose):
if pcMove == 1:
    print("Your opponent has choosen Fury Punch")
    print("it is a tie there is no winner")
    r = tie
elif pcMove == 2:
    print("Your opponent has choosen Punishment Kick")
    print("You have lost")
    r = lose
elif pcMove == 3:
    print("Your opponent has choosen Sword of Justice")
    print("You have lost")
    r = lose
elif pcMove == 4:
    print("Your opponent has choosen Shuriken of Vengeance")
    print("You have won. Good job")
    r = win
elif pcMove == 5:
    print("Your opponent has choosen Numchucks of Anger")
    print("You have won. Good job")
    r = win
else:
    print("Your opponent has choosen Knife of Freedom")
    print("You have lost")
    r = lose
return(r)

def attack2(pcMove, win, tie, lose):
if pcMove == 1:
    print("Your opponent has choosen Fury Punch")
    print("You have won. Good job")
    r = win
elif pcMove == 2:
    print("Your opponent has choosen Punishment Kick")
    print("it is a tie there is no winner")
    r = tie
elif pcMove == 3:
    print("Your opponent has choosen Sword of Justice")
    print("You have lost")
    r = lose
elif pcMove == 4:
    print("Your opponent has choosen Shuriken of Vengeance")
    print("You have lost")
    r = lose
elif pcMove == 5:
    print("Your opponent has choosen Numchucks of Anger")
    print("You have won. Good job")
    r = win
else:
    print("Your opponent has choosen Knife of Freedom")
    print("You have lost")
    r = lose
return(r)

def attack3(pcMove, win, tie, lose):
if pcMove == 1:
    print("Your opponent has choosen Fury Punch")
    print("You have won. Good job")
    r = win
elif pcMove == 2:
    print("Your opponent has choosen Punishment Kick")
    print("You have won. Good job")
    r = win
elif pcMove == 3:
    print("Your opponent has choosen Sword of Justice")
    print("it is a tie there is no winner")
    r = tie
elif pcMove == 4:
    print("Your opponent has choosen Shuriken of Vengeance")
    print("You have lost")
    r = lose
elif pcMove == 5:
    print("Your opponent has choosen Numchucks of Anger")
    print("You have lost")
    r = lose
else:
    print("Your opponent has choosen Knife of Freedom")
    print("You have won. Good job")
    r = win
return(r)

def attack4(pcMove, win, tie, lose):
if pcMove == 1:
    print("Your opponent has choosen Fury Punch")
    print("You have lost")
    r = lose
elif pcMove == 2:
    print("Your opponent has choosen Punishment Kick")
    print("You have won. Good job")
    r = win
elif pcMove == 3:
    print("Your opponent has choosen Sword of Justice")
    print("You have won. Good job")
    r = win
elif pcMove == 4:
    print("Your opponent has choosen Shuriken of Vengeance")
    print("it is a tie there is no winner")
    r = tie
elif pcMove == 5:
    print("Your opponent has choosen Numchucks of Anger")
    print("You have lost")
    r = lose
else:
    print("Your opponent has choosen Knife of Freedom")
    print("You have won. Good job")
    r = win
return(r)

def attack5(pcMove, win, tie, lose):
if pcMove == 1:
    print("Your opponent has choosen Fury Punch")
    print("You have lost")
    r = lose
elif pcMove == 2:
    print("Your opponent has choosen Punishment Kick")
    print("You have lost")
    r = lose
elif pcMove == 3:
    print("Your opponent has choosen Sword of Justice")
    print("You have won. Good job")
    r = win
elif pcMove == 4:
    print("Your opponent has choosen Shuriken of Vengeance")
    print("You have won. Good job")
    r = win
elif pcMove == 5:
    print("Your opponent has choosen Numchucks of Anger")
    print("it is a tie there is no winner")
    r = tie
else:
    print("Your opponent has choosen Knife of Freedom")
    print("You have lost")
    r = lose
return(r)

def attack6(pcMove, win, tie, lose):
if pcMove == 1:
    print("Your opponent has choosen Fury Punch")
    print("You have won. Good job")
    r = win
elif pcMove == 2:
    print("Your opponent has choosen Punishment Kick")
    print("You have won. Good job")
    r = win
elif pcMove == 3:
    print("Your opponent has choosen Sword of Justice")
    print("You have lost")
    r = lose
elif pcMove == 4:
    print("Your opponent has choosen Shuriken of Vengeance")
    print("You have lost")
    r = lose
elif pcMove == 5:
    print("Your opponent has choosen Numchucks of Anger")
    print("You have won. Good job")
    r = win
else:
    print("Your opponent has choosen Knife of Freedom")
    print("it is a tie there is no winner")
    r = tie
return(r)

def winLose(attack, win, tie, lose):
import random
pcMove = random.randint(1, 6);
while pcMove == 0:
    pcMove = random.randint(1, 6);
if attack == 1:
    print("You have choosen to use Fury Punch. Good Luck")
    print("Ready for battle. Press enter to start")
    enter = input()
    attack1(pcMove, win, tie, lose)
    r = win or lose or tie
elif attack == 2:
    print("You have choosen to use Punishment Kick. Good Luck")
    print("Ready for battle. Press enter to start")
    enter = input()
    attack2(pcMove, win, tie, lose)
    r = win or lose or tie
elif attack == 3:
    print("You have choosen to use Sword of Justice. Good Luck")
    print("Ready for battle. Press enter to start")
    enter = input()
    attack3(pcMove, win, tie, lose)
    r = win or lose or tie
elif attack == 4:
    print("You have choosen to use Shuriken of Vengence. Good Luck")
    print("Ready for battle. Press enter to start")
    enter = input()
    attack4(pcMove, win, tie, lose)
    r = win or lose or tie
elif attack == 5:
    print("You have choosen to use Numchucks of Anger. Good Luck")
    print("Ready for battle. Press enter to start")
    enter = input()
    attack5(pcMove, win, tie, lose)
    r = win or lose or tie
else: 
    print("You have choosen to use Knife of Freedom. Good Luck")
    print("Ready for battle. Press enter to start")
    enter = input()
    attack6(pcMove, win, tie, lose)
    r = win or lose or tie
return(r)

def instructions(name):
print("Welcome to Ultimate Ninja Combat!!!" + name)
print("You will be playing against the computer, and the winner gets bragging rights. Before each match you will have to place a bet which must be an amount which must be a multiple of 5. if you win you get that amount back from the computer. if you lose you lose the money. if your amount drops to zero you will be removed from the game")
print("you will start with 100 dollars use it wisely")
print("Each turn you will be asked to pick one of the following attacks")
print("(1)Fury Punch")
print("(2)Punishment kick")
print("(3)Sword of justice")
print("(4)Shuriken of Vengence")
print("(5)Numchucks of Anger")
print("(6)Knife of Freedom")
print("choose wisely")
print("  ")
print("  ")
print("  ")

def gameplay(balance):
while True:
    print("Place your bet. Must be a multiple of 5")
    posBets = range(5, (balance + 1), 5)
    bet = str(input())
    if bet == posBets:
        print("You have bet $" + str(bet))
        loop = 0
    elif bet != posBets:
            print("Please bet an amount that is a multiple of 5, or an amount that is within your balance")
            print("Press enter to continue")
            input()
            loop = 1
    if not(loop == 1):break #Exit loop
    return(bet)
win = 1
lose = 2
tie = 3
r = win or lose or tie
print("Battle shall now commence")
print("Choose an attack")
print("The attacks you can use are as follows")
print("(1)Fury Punch")
print("(2)Punishment kick")
print("(3)Sword of justice")
print("(4)Shuriken of Vengence")
print("(5)Numchucks of Anger")
print("(6)Knife of Freedom")
attack = int(input())
while attack < 1 or attack > 6:
    print("please input either: 1, 2, 3, 4, 5 or 6")
    attack = int(input())
winLose(attack, win, lose, tie,)
if r == win:
    newBalance = int(balance) + int(bet)
elif r == lose:
    newBalance = int(balance) - int(bet)
else:
    if r == tie:
        balance = newBalance 
print("Your Balance is $" + str(newBalance))
return(bet, newBalance)

def menu(name):
    balance = 100
    while True:
        newBalance = balance
        print("Your current balance is $" + str(balance))
        print("Choose an option " + name)
        print("(I)nstructions")
        print("(P)lay game")
        print("(Q)uit game")
        print("Please Input I,P or Q")
        menuChoice = input()            
        if menuChoice == "i" or menuChoice == "I":
            instructions(name)
            loop = 1
        elif menuChoice == "p" or menuChoice == "P":
            gameplay(balance)

            loop = 1
            print("Press enter to contiue")
            enter = input()
        elif menuChoice == "q" or menuChoice == "Q":
            loop = 0
        else:                   
            print("I did not understand the response. Please Input I, P or Q")
            print("Press enter to continue")
            enter = input()
            loop = 1
        if not(loop == 1): break    #Exit loop
    return(menuChoice)

def main():
print("Welcome to Ultimate Ninja Combat!!! What is your name?")
name = input()
print ("Welcome " + name)
menu(name)
def攻击1(移动、赢、平、输):
如果pcMove==1:
打印(“你的对手选择了狂怒拳”)
打印(“这是一个平局,没有赢家”)
r=平局
elif pcMove==2:
打印(“你的对手选择了惩罚踢”)
打印(“您已丢失”)
r=失去
elif pcMove==3:
打印(“你的对手选择了正义之剑”)
打印(“您已丢失”)
r=失去
elif pcMove==4:
打印(“你的对手选择了复仇之神舒利肯”)
打印(“你赢了,干得好”)
r=赢
elif pcMove==5:
打印(“你的对手选择了愤怒的数字”)
打印(“你赢了,干得好”)
r=赢
其他:
打印(“你的对手选择了自由之刀”)
打印(“您已丢失”)
r=失去
返回(r)
def攻击2(移动、赢、平、输):
如果pcMove==1:
打印(“你的对手选择了狂怒拳”)
打印(“你赢了,干得好”)
r=赢
elif pcMove==2:
打印(“你的对手选择了惩罚踢”)
打印(“这是一个平局,没有赢家”)
r=平局
elif pcMove==3:
打印(“你的对手选择了正义之剑”)
打印(“您已丢失”)
r=失去
elif pcMove==4:
打印(“你的对手选择了复仇之神舒利肯”)
打印(“您已丢失”)
r=失去
elif pcMove==5:
打印(“你的对手选择了愤怒的数字”)
打印(“你赢了,干得好”)
r=赢
其他:
打印(“你的对手选择了自由之刀”)
打印(“您已丢失”)
r=失去
返回(r)
def攻击3(移动、赢、平、输):
如果pcMove==1:
打印(“你的对手选择了狂怒拳”)
打印(“你赢了,干得好”)
r=赢
elif pcMove==2:
打印(“你的对手选择了惩罚踢”)
打印(“你赢了,干得好”)
r=赢
elif pcMove==3:
打印(“你的对手选择了正义之剑”)
打印(“这是一个平局,没有赢家”)
r=平局
elif pcMove==4:
打印(“你的对手选择了复仇之神舒利肯”)
打印(“您已丢失”)
r=失去
elif pcMove==5:
打印(“你的对手选择了愤怒的数字”)
打印(“您已丢失”)
r=失去
其他:
打印(“你的对手选择了自由之刀”)
打印(“你赢了,干得好”)
r=赢
返回(r)
def攻击4(移动、赢、平、输):
如果pcMove==1:
打印(“你的对手选择了狂怒拳”)
打印(“您已丢失”)
r=失去
elif pcMove==2:
打印(“你的对手选择了惩罚踢”)
打印(“你赢了,干得好”)
r=赢
elif pcMove==3:
打印(“你的对手选择了正义之剑”)
打印(“你赢了,干得好”)
r=赢
elif pcMove==4:
打印(“你的对手选择了复仇之神舒利肯”)
打印(“这是一个平局,没有赢家”)
r=平局
elif pcMove==5:
打印(“你的对手选择了愤怒的数字”)
打印(“您已丢失”)
r=失去
其他:
打印(“你的对手选择了自由之刀”)
打印(“你赢了,干得好”)
r=赢
返回(r)
def攻击5(移动、赢、平、输):
如果pcMove==1:
打印(“你的对手选择了狂怒拳”)
打印(“您已丢失”)
r=失去
elif pcMove==2:
打印(“你的对手选择了惩罚踢”)
打印(“您已丢失”)
r=失去
elif pcMove==3:
打印(“你的对手选择了正义之剑”)
打印(“你赢了,干得好”)
r=赢
elif pcMove==4:
打印(“你的对手选择了复仇之神舒利肯”)
打印(“你赢了,干得好”)
r=赢
elif pcMove==5:
打印(“你的对手选择了愤怒的数字”)
打印(“这是一个平局,没有赢家”)
r=平局
其他:
打印(“你的对手选择了自由之刀”)
打印(“您已丢失”)
r=失去
返回(r)
def攻击6(移动、赢、平、输):
如果pcMove==1:
打印(“你的对手选择了狂怒拳”)
打印(“你赢了,干得好”)
r=赢
elif pcMove==2:
打印(“你的对手选择了惩罚踢”)
打印(“你赢了,干得好”)
r=赢
elif pcMove==3:
打印(“你的对手选择了正义之剑”)
打印(“您已丢失”)
r=失去
elif pcMove==4:
打印(“你的对手选择了复仇之神舒利肯”)
打印(“您已丢失”)
r=失去
elif pcMove==5:
打印(“你的对手选择了愤怒的数字”)
打印(“你赢了,干得好”)
r=赢
其他:
打印(“你的对手选择了自由之刀”)
打印(“这是一个平局,没有赢家”)
r=平局
返回(r)
def输赢(攻击、赢、平、输):
随机输入
pcMove=random.randint(1,6);
当pcMove==0时:
pcMove=random.randint(1,6);
如果攻击=1:
打印(“您已选择使用愤怒冲孔。祝您好运”)
    bet = int(input())
    if bet in posBets:
bet = int(input())