我正在编写一个代码来玩幸运七人制。在 IDLE 中运行模块时,我在“导入随机”之后立即收到错误。我可以直接在 IDLE 中输入“import random”,它可以正常工作,但我无法运行整个模块,这意味着我无法测试整个代码。
继承人的代码:
import random
count = 0
pot = int(input("How much money would you like to start with in your pot? "))
if pot>0 and pot.isdigit():
choice = input("Would you like to see the details of where all of your money went? yes, or no? ")
if choice == ("yes", "Yes", "YES", "ya", "Ya", "y", "Y")
while pot>0:
roll1 = random.randint(1, 7)
roll2 = random.randint(1, 7)
roll = (roll1)+(roll2)
count += 1
maxpot = max(pot)
if roll == 7:
pot +=4
print("Your rolled "+str(roll1)" and "+str(roll2)". That's "+str(roll)"! You get $4! Your pot is now at $"+str(pot))
else:
pot -= 1
print("Your rolled "+str(roll1)" and "+str(roll2)". That's "+str(roll)". You loose a dollar... Your pot is now at $"+str(pot))
print("Oh no! Your pot is empty! It took "+str(count)" rounds! Your maximum pot was $"+str(maxpot)"!")
elif choice == ("no", "No", "No", "n", "N"):
while pot>0:
roll1 = random.randint(1, 7)
roll2 = random.randint(1, 7)
roll = (roll1)+(roll2)
count += 1
maxpot = max(pot)
if roll == 7:
pot +=4
else:
pot -= 1
print("Oh no! Your pot is empty! It took "+str(count)" rounds! Your maximum pot was $"+str(maxpot)"!")
else:
print("You did not enter 'yes' or 'no'. Be sure and type either 'yes' or 'no' exactly like that. Lets try agian!")
restart_program
else:
print("Please enter a positive dollar amount.")
restart_program