我开发了一个简单的 Python 骰子游戏,用户可以在其中玩游戏,直到他们对“让我们玩游戏:是或否”说“不”。还有一些输入,比如你想玩多少个骰子(单骰子或双骰子),你想要这些骰子有多少面。此外,如果用户输入有多少个骰子 >2 或 <1 或边数 >6 或 <1,程序应发出警告消息。
牢记这一点,我写了一些代码,但输出不知何故出错了。当我切换到单个骰子时,程序会自动停止。
Welcome to the Dice Game for Single Players
Lets play the Game : yes or no yes
Please Enter your Name: maddy
Hi maddy How Many Dice you want to play with?? 1 0r 2 : 2
maddy , How Many sides you want in a dice out of 1 to 6 : 6
Hey maddy your throw count is 1 and your dice pair is (2, 5) & total = 7
Lets play the Game : yes or no yes
Hi maddy How Many Dice you want to play with?? 1 0r 2 : 2
maddy , How Many sides you want in a dice out of 1 to 6 : 5
Hey maddy your throw count is 2 and your dice pair is (2, 5) & total = 7
Lets play the Game : yes or no yes
Hi maddy How Many Dice you want to play with?? 1 0r 2 : 1
maddy , How Many sides you want in a dice out of 1 to 6 : 5
Process finished with exit code 0
import random
print('Welcome to the Dice Game for Single Players')
a=input('Lets play the Game : yes or no ')
if a== 'no':
print('OOPS!! May be u can check other games u r interested in here')
elif a=='yes':
b=str(input('Please Enter your Name: '))
c=int(input(f'Hi {b} How Many Dice you want to play with?? 1 0r 2 : '))
while c<1 or c>2:
print('Dice value should be 1 0r 2')
c = int(input(f'Hi {b} How Many Dice you want to play with?? 1 0r 2 : '))
d=int(input(f'{b} , How Many sides you want in a dice out of 1 to 6 : '))
dice_count = 0
dice_total = 0
repeater=True
while a== 'yes' and c==1 and repeater:
x=random.randint(1,d)
dice_total = 0
dice_count=dice_count+1
dice_total=dice_total+x
print(f'Hey {b} your throw count is {dice_count} and your dice number is {dice_total}')
a = input('Lets play the Game : yes or no ')
if a=='yes':
c = int(input(f'Hi {b} How Many Dice you want to play with?? 1 0r 2 : '))
d = int(input(f'{b} , How Many sides you want in a dice out of 1 to 6 : '))
repeater=True
elif a=='no':
print('OOPS!! May be u can check other games u r interested in here')
while a == 'yes' and c == 2 and repeater:
y=random.randint(1,d)
z=random.randint(1,d)
two=(y,z)
dice_count = dice_count + 1
dice_total=0
dice_total = dice_total + sum(two)
print(f'Hey {b} your throw count is {dice_count} and your dice pair is {two} & total = {dice_total}')
a = input('Lets play the Game : yes or no ')
if a == 'yes':
c = int(input(f'Hi {b} How Many Dice you want to play with?? 1 0r 2 : '))
d = int(input(f'{b} , How Many sides you want in a dice out of 1 to 6 : '))
repeater = True
elif a == 'no':
print('OOPS!! May be u can check other games u r interested in here')