| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1561 人关注过本帖
标题:照书本上抄的代码,为啥不运行?
只看楼主 加入收藏
greenpop
Rank: 1
等 级:新手上路
帖 子:83
专家分:3
注 册:2011-12-22
结帖率:89.19%
收藏
 问题点数:0 回复次数:2 
照书本上抄的代码,为啥不运行?
responses={}

polling_active=True

while polling_active:
    name=input("\nWhat is your name?")
    response=input("which mountain would you like to climp 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 Result---")
for name,response in response.items():
    print(name+" would like to climb"+response+".")


错误信息:

What is your name?zwg

Traceback (most recent call last):
  File "F:/pythonst/mountain_poll.py", line 6, in <module>
    name=input("\nWhat is your name?")
  File "<string>", line 1, in <module>
NameError: name 'zwg' is not defined
>>>
搜索更多相关主题的帖子: like 代码 input name response 
2019-11-06 10:35
fall_bernana
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:17
帖 子:244
专家分:2106
注 册:2019-8-16
收藏
得分:0 
回复 楼主 greenpop
程序代码:
#-*- coding:utf-8 -*-  
responses={}
polling_active=True
while polling_active:
    name=input("\nWhat is your name?  ")
    response=input("which mountain would you like to climp 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 Result---")
for name,response in responses.items():
    print(name+" would like to climb"+response+".")

由于没有遇到你说的这个问题. 你按这个试试.如果没问题,对比看看哪里的问题

[此贴子已经被作者于2019-11-6 12:28编辑过]

2019-11-06 12:09
greenpop
Rank: 1
等 级:新手上路
帖 子:83
专家分:3
注 册:2011-12-22
收藏
得分:0 
在python 2 上运行老出错。在python3上运行正常。谢谢楼上。
2019-11-06 17:08
快速回复:照书本上抄的代码,为啥不运行?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021676 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved