我想写一个掷骰子的程序。这就是我所拥有的:
import random
print("You rolled",random.randint(1,6))
我也希望能够做这样的事情:
print("Do you want to roll again? Y/N")
如果我按下Y,它会再次滚动,如果我按下N,就会退出应用程序。提前感谢!
发布于 2018-01-08 00:52:56
import random
min = 1
max = 6
roll_again = "yes"
roll_again = raw_input
while roll_again == "yes" or roll_again == "y":
print ("Rolling the dices...")
print ("The values are....")
print (random.randint(min, max))
print (random.randint(min, max))
roll_again = raw_input("Roll the dices again?")
发布于 2018-03-17 19:03:43
这是针对python 3的。
import random
repeat="Y"
while repeat == "Y":
print("Rolling the dice")
print(random.randint(1,6))
repeat =input("Do you wanna roll again Y/N?")
if repeat=="Y":
continue
发布于 2018-04-19 02:02:20
我三天前才开始学习Python,但这是我为Python3想出来的,它是有效的:
import random
question = input('Would you like to roll the dice [y/n]?\n')
while question != 'n':
if question == 'y':
die1 = random.randint(1, 6)
die2 = random.randint(1, 6)
print(die1, die2)
question = input('Would you like to roll the dice [y/n]?\n')
else:
print('Invalid response. Please type "y" or "n".')
question = input('Would you like to roll the dice [y/n]?\n')
print('Good-bye!')
https://stackoverflow.com/questions/44008489
复制相似问题