| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
共有 114 人关注过本帖
标题:照书本上抄的代码,为啥不运行?
只看楼主 加入收藏
greenpop
Rank: 1
等 级:新手上路
帖 子:55
专家分:3
注 册:2011-12-22
结帖率:86.96%
  问题点数: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 
【推荐】大型监控、工控、组态VC++./C#源码组件库2019下载!
【推荐】超50万数控、建模仿真、电力VC++/.NET图形源码库下载!
【推荐】专业CAD\GIS\业务流程VC++/C#可视化图形软件源码库下载!
2019-11-06 10:35
fall_bernana
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:3
帖 子:65
专家分:552
注 册: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
等 级:新手上路
帖 子:55
专家分:3
注 册:2011-12-22
  得分:0 
在python 2 上运行老出错。在python3上运行正常。谢谢楼上。
2019-11-06 17:08
快速回复:照书本上抄的代码,为啥不运行?
数据加载中...
 
   



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

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