嗨,我是python和linux的初学者。即时通讯使用visual studio代码和python 3.5.2 我试图运行一些非常简单的失败。 TNX 所以这是我的代码:
import random
def randomNumber():
n=random.randint(1,100)
print (n)
checkMatch(n)
def checkMatch(compNum):
playerNum= int(input("choose num between 1 to 100: "))
if playerNum==compNum:
print ("congratulation you won!")
elif playerNum<compNum:
print ("sorry but the num you choose is smaller then the right answer")
else:
print("sorry but the num you choose is bigger then the right answer")
答案 0 :(得分:1)
所提供的代码没有任何预期可以运行的代码。你定义了两个函数,但它们从未调用过,因此没有任何反应。
尝试在最后添加randomNumber()
,我认为该程序将按预期工作。
答案 1 :(得分:1)
您没有调用该函数来运行。将randomNumber()
添加到程序的末尾。您的if
声明是否收到错误?如果你是的话,请编辑你的帖子。它对我来说很好。