zoukankan      html  css  js  c++  java
  • 使用用户输入来填充字典

    >>> tag = True
    >>> test1 = {}
    >>> type(test1)
    <class 'dict'>
    >>> while tag:
        name = input("please input your name: ")
        mountain = input("which mountain to you want to climb next sunday ? ")
        test1[name] = mountain
        repeat = input("would you like another person to attend poll? yes or no?")
        if repeat == "no":
            tag = False
    
            
    please input your name: zhangsan
    which mountain to you want to climb next sunday ? taishan
    would you like another person to attend poll? yes or no?yes
    please input your name: lisi
    which mountain to you want to climb next sunday ? songshan
    would you like another person to attend poll? yes or no?yes
    please input your name: wangwu
    which mountain to you want to climb next sunday ? huashan
    would you like another person to attend poll? yes or no?no
    >>> test1
    {'zhangsan': 'taishan', 'lisi': 'songshan', 'wangwu': 'huashan'}
    >>> for i,j in test1.items():
        print(i,"",j)
    
        
    zhangsan → taishan
    lisi → songshan
    wangwu → huashan
  • 相关阅读:
    Python语言程序设计(1)--实例1和基本知识点
    前端学习笔记--函数
    知乎推荐书籍整理
    第六周周总结
    第五周总结
    第四周周总结
    第三周周总结
    第二周总结
    第一周总结
    项目目标
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14223685.html
Copyright © 2011-2022 走看看