繁体   English   中英

Python Traceback(最近一次通话最后一次)

[英]Python Traceback (most recent call last)

掷骰子是在赌场玩的流行骰子游戏。

编写一个 python 程序来玩游戏的变体,如下所示:掷两个骰子。 每个骰子有六个面,分别代表值 1、2、3、4、5 和 6。检查两个骰子的总和。 如果总和是 2、3 或 12(称为掷骰子),则您输; 如果总和是 7 或 11(称为自然),则您获胜; 如果总和是另一个值(即 4、5、6、8、9 或 10),则建立一个点,然后您继续掷骰子,直到掷出 7 或相同的点值。 如果掷出 7,你输,如果你掷出点值,你就赢了。

    import random

def rollDice():
    dice1=random.randint(1,6)
    dice2=random.randint(1,6)
    return dice1, dice2
    
def determine_win_or_lose(dice1,dice2):
    dice1=random.randint(1,6)
    dice2=random.randint(1,6)
    sum=dice1+dice2
    print("You rolled %d + %d = %d"%(dice1,dice2,sum))
    if sum==2 or sum==3 or sum==12: 
        lose=lose+1 
    elif sum==7 or sum==11: 
        win=win+1 
    else:
        print("point is %d"%(sum))
        determinePointValueResult()
        p=sum 
        print("You rolled",dice1,"+",dice2,"=",sum) 
        p1=p 
        if sum==p: 
            win=win+1 
            print("You Win") 
            print("\n\n") 
        else: 
            lose=lose+1 
            print("You lose") 
            print("\n\n") 
    return sum
    
def determinePointValueResult(point):
    while sum!=7 and sum!=point:
        rollDice()
        dice1=random.randint(1,6) 
        dice2=random.randint(1,6) 
        sum=dice1+dice2
        if sum == point:
            win=win+1
            break
        elif sum == 7:
            lose=lose+1
            break
        print("You rolled",dice1,"+",dice2,"=",sum)
    return sum
   
if __name__ == "__main__":
    
    win=0
    lose=0
    nmbr=input("How many games do you want to play > ")
    for I in number:
        rollDice()
        determine_win_or_lose(win,lose)
        if win:
            win=win+1
            print('You win')
            break
        else:
            lose=lose+1
            print('You lose')
            break
    print(win,"Wins and",lose,"losses")```
import random

def rollDice():
    dice1=random.randrange(1,7)
    dice2=random.randrange(1,7)
    sum=dice1+dice2
    return sum
def determinePointValueResult(point):
    sum = 0
    while True:
        sum = determine_win_or_lose()
        if sum == point:
            print("You won!")
            break
        elif sum == 7:
            print("You lose!")
            break
        else:
            continue
def determine_win_or_lose():
    sum = 0
    dice1=0
    dice2=0
    dice1=random.randint(1,6)
    dice2=random.randint(1,6)
    sum=dice1+dice2
    print("You rolled %d + %d = %d"%(dice1,dice2,sum))
    return sum
if _name_ == "_main_":
    nmbr=input("How many games do you want to play > ")
    for i in nmbr:
        rollDice()
        determine_win_or_lose()
        win=0 
        lose=0
        print("")
        for i in range(1,7): 
            a=random.randrange(1,7) 
            b=random.randrange(1,7) 
            c=a+b 
            if c==7 or c==11: 
                win=win+1 
                print("You rolled",a,"+",b,"=",c) 
                print("You Win") 
                print("\n\n") 
            elif c==2 or c==3 or c==12: 
                lose=lose+1 
                print("You rolled",a,"+",b,"=",c) 
                print("You Lose") 
                print("\n\n") 
            elif c==4 or c==5 or c==6 or c==8 or c==9 or c==10: 
                p=c 
                print("You rolled",a,"+",b,"=",c) 
                p1=p 
                while c!=7: 
                    print("point is",p1) 
                    a=random.randrange(1,7) 
                    b=random.randrange(1,7) 
                    c=a+b 
                    print("You rolled",a,"+",b,"=",c) 
                    if c==p: 
                        win=win+1 
                        print("You Win") 
                        print("\n\n") 
                        break 
                    elif c==7: 
                        lose=lose+1 
                        print("You lose") 
                        print("\n\n") 
                        break 
                    else: 
                        continue 
                    
print("Game results: ",win," and ",lose,"losses")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM