当我尝试运行此模块时
from import random
def guessnum():
randomnum = random.randint(1,6)
awnser = input ("what do you think the number is? ")
if awnser==randomnum:
print ("good job. you are correct. ")
else:
print ("incorrect. better luck next time. ")
restart = input ("would you like to try again? ")
if restart = Yes or y:
guessnum()
else:
end()
我的语法高亮显示导入。
问题是什么?
我已经尝试import random
,但似乎不想工作
答案 0 :(得分:0)
修复了缩进,拼写,大小写,插入不必要的空格以及string
和int
之间的比较,这些内容总是错误的。
还添加了str.title
以允许restart
import random
import sys
def guessnum():
random_num = random.randint(1,6)
answer = int(input("What do you think the number is? "))
if answer == random_num:
print("Good job. you are correct!")
else:
print("Incorrect. Better luck next time. The number was %d" % random_num)
restart = input("Would you like to try again? ")
if restart.title() in ["Yes", "Y"]:
guessnum()
else:
end()
def end():
print("Goodbye!")
sys.exit(0)
guessnum()
答案 1 :(得分:0)
您的代码充满了错误。我修复了缩进和其他语法问题。
您不需要使用,只需使用10, 25 and 16;
。
这是代码
import random