|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 chenlunyong1213 于 2018-12-8 21:55 编辑
大家好,我又来了。
这次发现了一个诡异的事情,我按照书本的逻辑,完成一个代码:
设计一个调查问卷,询问用户name,爬山的每周次数,收集数据到一个集合。
我的代码内容如下:
#设计一个调查问卷,询问用户name,爬山的每周次数,收集数据到一个集合。
go_on="True"
severy={}
while go_on=="True":
name=input("please type your name?\n")
answer=input("how times are you clamp every week?\n")
severy[name]=answer
go_onmark=input("please tell me whether you want to go on serve??\n Please Type (Yes/No) \n")
if go_onmark=="no":
go_on="False"
这个运行是正常的,但是按照书本的代码,运行的时候,出现了不能判断,无法进入go_onmark的判断环节,一直循环下去,书本的代码如下:
responses = {}
# 设置一个标志,指出调查是否继续
polling_active = True
while polling_active:
# 提示输入被调查者的名字和回答
 name = input("\nWhat is your name? ")
response = input("Which mountain would you like to climb someday? ")
# 将答卷存储在字典中
 responses[name] = response
# 看看是否还有人要参与调查
 repeat = input("Would you like to let another person respond? (yes/ no) ")
if repeat == 'no':
polling_active = False
# 调查结束,显示结果
print("\n--- Poll Results ---")
 for name, response in responses.items():
print(name + " would like to climb " + response + ".")
请大神帮忙看一下是不是哪里出了问题???谢谢!
go_on=True
go_on=False
不要加引号
go_on=='False' #这里go_on是字符串,所以会一直循环
|
|