鱼C论坛

 找回密码
 立即注册
查看: 1410|回复: 4

[已解决]为什么总是查无此人呢

[复制链接]
发表于 2018-3-29 22:14:24 | 显示全部楼层 |阅读模式

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

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

x

while 1:
    order = int(input('请输入相关的密码指令: '))
    contacts = dict()



    if order == 1:
        name = input('请输入联系人姓名: ')
        if name in contacts:
            print(name,':',contacts[name])
        else:
            print('Sorry,查无此人!')



    if order == 2:
        name = input('请输入联系人姓名: ')
        if name in contacts:
            print('您输入的姓名已存在 --->>>',name,':',contacts[name])
            option = input('是否修改联系人资料(Yes or No)')
            if option == 'Yes':
                newnumber = int(input('请输入新的联系人号码:'))
                contacts[name] = newnumber

        else:
            number = int(input('请输入联系人号码: '))
            contacts[name] = number



    if order == 3:
        name = input('请输入联系人姓名: ')
        del contacts[name]



    if order == 4:
        print('|---感谢使用通讯录小程序---|')
        break

大神们帮忙看一下,明明已经储存过一个数据,为什么还是查无此人呢?
非常感谢谢
最佳答案
2018-3-29 23:07:11
contacts = dict()  每次都清空了
  1. contacts = dict()


  2. while 1:
  3.     order = int(input('请输入相关的密码指令: '))
  4.    



  5.     if order == 1:
  6.         name = input('请输入联系人姓名: ')
  7.         if name in contacts:
  8.             print(name,':',contacts[name])
  9.         else:
  10.             print('Sorry,查无此人!')



  11.     if order == 2:
  12.         name = input('请输入联系人姓名: ')
  13.         if name in contacts:
  14.             print('您输入的姓名已存在 --->>>',name,':',contacts[name])
  15.             option = input('是否修改联系人资料(Yes or No)')
  16.             if option == 'Yes':
  17.                 newnumber = int(input('请输入新的联系人号码:'))
  18.                 contacts[name] = newnumber

  19.         else:
  20.             number = int(input('请输入联系人号码: '))
  21.             contacts[name] = number



  22.     if order == 3:
  23.         name = input('请输入联系人姓名: ')
  24.         del contacts[name]



  25.     if order == 4:
  26.         print('|---感谢使用通讯录小程序---|')
  27.         break
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-3-29 22:18:22 From FishC Mobile | 显示全部楼层
每次循环都把字典清空了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2018-3-29 22:31:59 | 显示全部楼层
本帖最后由 不知现在几点 于 2018-3-29 22:34 编辑

没问题
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-3-29 22:32:52 | 显示全部楼层
我试过没问题
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-3-29 23:07:11 | 显示全部楼层    本楼为最佳答案   
contacts = dict()  每次都清空了
  1. contacts = dict()


  2. while 1:
  3.     order = int(input('请输入相关的密码指令: '))
  4.    



  5.     if order == 1:
  6.         name = input('请输入联系人姓名: ')
  7.         if name in contacts:
  8.             print(name,':',contacts[name])
  9.         else:
  10.             print('Sorry,查无此人!')



  11.     if order == 2:
  12.         name = input('请输入联系人姓名: ')
  13.         if name in contacts:
  14.             print('您输入的姓名已存在 --->>>',name,':',contacts[name])
  15.             option = input('是否修改联系人资料(Yes or No)')
  16.             if option == 'Yes':
  17.                 newnumber = int(input('请输入新的联系人号码:'))
  18.                 contacts[name] = newnumber

  19.         else:
  20.             number = int(input('请输入联系人号码: '))
  21.             contacts[name] = number



  22.     if order == 3:
  23.         name = input('请输入联系人姓名: ')
  24.         del contacts[name]



  25.     if order == 4:
  26.         print('|---感谢使用通讯录小程序---|')
  27.         break
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-9-28 02:40

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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