如何编写掷骰子游戏项目. 这是我的第一个项目



我写了正确的代码吗

no1 = 1
no2 = 6
enter code here
dice = input("enter number: "):
no1 = int(input("enter number one: "))
no2 = int(input("enter number two: "))
print("you have enter "+str(no1))
print("you have enter "+str(no2))
if dice == "5":
print("you want to roll again")
elif dice == "6":
print("roll dice automatically")

检查您是否没有错误地将所有问题格式化为代码

编写掷骰子程序的方法有很多种。但是,最简单的方法是使用称为 random 的内置库。下面我已经修复并清理了代码:

import random # The libary used from generating random numbers
def dice_roll(): # function usedto reset the game
input("Press enter to roll the dice ") 
print("The dice rolled: ", random.randint(0,6)) 
UserInputNew = input ("Would you like to roll again? ") 
if UserInputNew == "5": 
print("n") # displays a blank line
dice_roll()
else:
print ("Thanks for playing!")
dice_roll() # loads the game

上面会做你想做的事。从上面的例子中,你有大量的输入,这些输入在掷骰子之类的东西中没有意义。如果您需要帮助理解代码的某些部分,那么我将非常乐意提供帮助。

对此有所帮助 爱丽丝、鲍勃和卡罗尔同意将他们的万圣节糖果汇集在一起,并在他们之间平均分配。为了他们的友谊,剩下的糖果都会被砸碎。例如,如果他们总共带回家 91 个糖果,他们将每人拿 30 个并粉碎 1 个。

在下面写一个算术表达式来计算他们必须砸碎多少糖果才能获得给定的运输。

最新更新