问题描述
限时送ChatGPT账号..是的,我知道已经有一篇文章介绍了这一点,但是当我阅读它时,它没有帮助,所以请不要将其标记为重复.
Yes I know that there is already a post covering this, but when I read it, it didn't help so please don't mark this as a duplicate.
我想编写一个程序,询问用户是否需要建议,如果他们输入否"或否",我希望它重复问题,如果他们输入是"或是",我希望它打印建议.我希望它包含一个 while 循环
I want to write a program that asks the user if they want advice and if they input "No" or "no" I want it to repeat the question and if they input "Yes" or "yes" I want it to print the advice. I want it to include a while loop
我曾尝试自己编写它,但无法使其正常工作.
I have tried to write it myself but I can't get it to work correctly.
有人知道吗?
来自 3.4 注释的代码 -
Code from the comment for 3.4 -
def doQuestion(question, advice):
reply = ("no")
while reply == "no":
print (question)
reply = input("Do you need some advice? ").lower()
if (reply == "yes"):
print ("Always listen to your IT teachers")
doQuestion("Do you want some advice?","Always listen to your IT teachers")
推荐答案
以下内容将持续检查用户是否需要有关问题的建议:
The following will keep on checking up on the user to see whether or not they need advice regarding a question:
def doTheyNeedAdvice(advice):
while raw_input("Do you need advice? ").lower() == "no":
pass
print (advice)
print "How old am I?"
doTheyNeedAdvice("I am old enough")
这篇关于使python重复一个字符串,直到输入Yes或yes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论