嗨我相当新的python并且无法在此程序中发现我的错误,我的错误看起来像这样
TypeError:hitormiss()缺少1个必需的位置参数: ' totalaim'
#!usr/bin/python3
import random
def takeshot(prompt='do you want to take shot?\n'):
answer = input(prompt)
if answer == ['yes', 'y']:
print("taking shot...")
else:
print("not-working")
def cal(randomnum = random.randrange(0, 100) , baseaim = 15):
totalaim = randomnum + baseaim
return totalaim
def hitormiss(totalaim, hit=50):
if totalaim >= hit:
print("You have hit your target!")
elif totalaim < hit:
print("You have missed your target!")
else:
print("Revise Code.")
takeshot()
cal()
hitormiss()
totalaim还没有在cal中声明吗?
答案 0 :(得分:0)
您应该删除cal()
和hitormiss()
函数调用,并将其替换为:
hitormiss(cal())
这是因为必须将参数传递给hitormiss()
,而cal()
会返回totalaim
值。
答案 1 :(得分:0)
此外,cal.totalaim
无法按照您的计划方式解决
def hitormiss(totalaim, hit=50):
if totalaim >= hit:
print("You have hit your target!")
elif totalaim < hit:
print("You have missed your target!")
else:
print("Revise Code.")
然后按照建议打电话
takeshot()
hitormiss(cal())