鱼C论坛

 找回密码
 立即注册
查看: 2415|回复: 2

python 编程如下

[复制链接]
发表于 2017-9-30 10:47:58 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
print('welcome using contect book')
print('1.查询联系人号码')
print('2.更改联系人信息')
print('3.删除联系人')
print('4.退出')

book=dict(wanglin=18061373966,yangshuyun=13572547035)
while 1:
    choice=input ('请选择你需要的服务:')
    if choice ==1:
        answer=input('请输入联系人的姓名:')
        if answer in book:
            print(book[answer])
        else:
            print('没有此联系人')
    if choice ==2:
        answer = input('请输入要更改的联系人姓名:')
        if answer in book:
            print(book[answer])
            r=input('你是否要更改',answer,'的电话号码yes/no?')
            if r == yes:
                s=input ('请输入新号码:')
                book.update(answer=s)
    if choice==3:
        answer = input('请输入你要删除的联系人姓名:')
        if answer in book:
            book.remove(answer)
        else:
            print('你选择的联系人不存在')
    if choice==4:
        print('您已选择退出')
        break
print("谢谢使用")
····························································································分割线
运行显示:
welcome using contect book
1.查询联系人号码
2.更改联系人信息
3.删除联系人
4.退出
请选择你需要的服务:1
请选择你需要的服务:12
请选择你需要的服务:3
请选择你需要的服务:4
请选择你需要的服务:

似乎进入了死循环,python菜鸟,求大神指导
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2017-9-30 10:54:36 | 显示全部楼层
input返回的是字符串,你用来和数值比较是否,不会相等的。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-9-30 11:13:59 | 显示全部楼层
  1. print('welcome using contect book')
  2. print('1.查询联系人号码')
  3. print('2.更改联系人信息')
  4. print('3.删除联系人')
  5. print('4.退出')

  6. book=dict(wanglin=18061373966,yangshuyun=13572547035)
  7. while 1:
  8.     choice=input ('请选择你需要的服务:')
  9.    
  10.     if choice.isdigit():
  11.         choice=int(choice)
  12.         
  13.         if choice ==1:
  14.             answer=input('请输入联系人的姓名:')
  15.             if answer in book:
  16.                 print(book[answer])
  17.         else:
  18.             print('没有此联系人')
  19.         if choice ==2:
  20.             answer = input('请输入要更改的联系人姓名:')
  21.             if answer in book:
  22.                 print(book[answer])
  23.                 r=input('你是否要更改',answer,'的电话号码yes/no?')
  24.                 if r == yes:
  25.                     s=input ('请输入新号码:')
  26.                     book.update(answer=s)
  27.         if choice==3:
  28.             answer = input('请输入你要删除的联系人姓名:')
  29.             if answer in book:
  30.                 book.remove(answer)
  31.             else:
  32.                 print('你选择的联系人不存在')
  33.         if choice==4:
  34.             print('您已选择退出')
  35.             break
  36. print("谢谢使用")
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-12-24 05:38

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表