def main():
c = 10
print("Welcome to Roderick's Chikkin and Gravy")
e = False
while not e:
x = input("Would you like some chikkin?: ")
gravy = input('Would you like some gravy?: ')
if gravy =="Y" or gravy == "y":
print('You get some chikkin and gravy!')
print("Got you some gravy! Enjoy")
if x == "Y" or x == "y":
c = f(c)
e = True
elif c == 0:
e = True
else:
e = True
c=0
c = f(c)
print("I hope you enjoyed your meal!")
def f(c):
if c > 0:
print("Got you some chikkin! Enjoy")
return c-1
else:
print("No chikkin left. Sorry")
return 0
main()
编写一个名为startingChikkin()的简单函数,该函数没有参数,只是询问用户我们从多少chikkin开始。如果用户键入正整数,则返回该值。如果不是,则重复提示,直到它们输入一个正整数,然后返回(请参阅前面有关输入验证的部分)-循环应该在函数内部。在main()程序开始时调用startingChikkin(),并将返回的值存储到您调用的变量中,以跟踪剩余chikkins的数量
在将来,请更清楚地告诉我你尝试了什么(而不是仅仅张贴你的代码)以及你的问题是什么。这是一个简单的问题。以下是您可以从描述中获得的一些要点:
描述清楚地表明,您需要一个名为
startingChikkin
不带参数的它还告诉你函数应该请求输入, 具体来说,它应该一直问,直到你得到正整数。 从这一点你知道,它应该要求输入,你应该 检查输入是否为正整数,如果不是,则继续询问 输入
它还告诉您函数应该返回这个正值 整数和
startingChikkin
函数应该有一个循环。 循环是必需的,因为您希望不断请求用户输入 直到它是正确的最后它告诉您应该从main调用
startingChikkin
函数并使用返回值计算剩余 小鸡。这意味着您应该有一个 可用的鸡和一个带有用户想要的鸡的变量, 你应该从startingChikkin
得到从这些观点你可以得出如下结论:
虽然我完全同意其他评论,但我很无聊,所以我为你的代码设计了一个可行的版本。这并不完全是你想要的,但你应该能够从中学习,如果没有别的
相关问题 更多 >
编程相关推荐