# coding=utf-8
name_l = []
passwd_l = []
money_l = []
goods = {}
index = 0
def input_user():
print("输入个人信息:")
while True:
name = input("name: ")
if name == "结束!":
break
passwd = input("passwd: ")
money = float(input("money: "))
name_l.append(name)
passwd_l.append(passwd)
money_l.append(money) def login():
print("登录:")
suc = False
while not suc:
name = input("name: ")
if name not in name_l:
print("用户名不存在")
continue
passwd = input("passwd: ") global index
index = name_l.index(name)
if passwd == passwd_l[index]:
print("登录成功")
suc = True
else:
print("密码错误") def input_goods():
print("商品:")
while True:
name_goods = input("goods_name: ")
if name_goods == "结束!":
break
price = input("price: ")
goods[name_goods] = int(price) def input_buy():
print("购买:")
while True:
name_goods = input("buy_goods_name: ")
if name_goods not in goods:
print("商品不存在!")
continue
amount = int(input("amount: "))
if money_l[index] < goods[name_goods] * amount:
print("余额不足")
break
else:
money_l[index] -= goods[name_goods] * amount
print("购买成功", "余额%f" % money_l[index]) input_user()
input_goods()
login()
input_buy()

Python列表和字典的简单实操例子的更多相关文章

  1. Python 列表生成式 & 字典生成式

    Python 列表生成式 & 字典生成式 通过生成式可以更加简洁地生成列表和字典 列表生成式 对比 直接生成数据后加入列表示例: user_list = list() for i in ran ...

  2. 【277】◀▶ Python 列表/元组/字典说明

    目录: 前言 一.访问列表中的值 二.更新列表 三.删除列表元素 四.Python 列表脚本操作符 五.Python 列表函数 & 方法 参考:Python 列表(List)使用说明 列表截取 ...

  3. python列表和字典的迭代

    1.列表和字典的迭代 程序开发中,对列表和字典进行迭代是非常常见的事情. 字典一般可以选择对key进行迭代.对value迭代和对key/value一起迭代 >>> d = {'a': ...

  4. Python 列表/元组/字典总结

    序列是Python中最基本的数据结构.序列中的每个元素都分配一个数字 - 它的位置,或索引,第一个索引是0,第二个索引是1,依此类推. Python有6个序列的内置类型,但最常见的是列表和元组. 序列 ...

  5. Python列表,元组,字典,字符串方法笔记

    01. 列表 1.1 列表的定义 List(列表) 是 Python 中使用 最频繁 的数据类型,在其他语言中通常叫做 数组 专门用于存储 一串 信息 列表用 [] 定义,数据 之间使用 , 分隔 列 ...

  6. Python列表,元组,字典,序列,引用

    1.列表 # Filename: using_list.py # This is my shopping list shoplist=["apple", "mango&q ...

  7. python 列表,字典,元组,字符串,常用函数

    飞机票 一.列表方法 1.ls.extend(object) 向列表ls中插入object中的每个元素,object可以是字符串,元组和列表(字符串“abc”中包含3个元组),相当于ls和object ...

  8. Python 列表,元组,字典

    0)字符串切片 py_str = 'python' >>>py_str[0] #取第一个字符串,返回值为"p",超出范围会报错 >>>py_st ...

  9. python 列表和字典的引用与复制(copy)

    列表或字典的引用: 引用针对变量的时候,传递引用后,对引用后的对象的值进行改变是不会影响到原值的:而列表不一样如: spam =42 cheese = spam spam =100 print(spa ...

随机推荐

  1. Pr制作音乐相册

    Pr制作音乐相册 设置蒙版效果

  2. GitKraken 快速配置 SSH Key

    快速使用 GitKraken 配置SSH keys git是现在最流行的版本管理工具,应用范围非常广泛,推荐一款git的可视化工具,这款 工具特别方便 它的官方如下https://www.gitkra ...

  3. openlayers按坐标点播放

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. How Many Answers Are Wrong HDU - 3038 带边权并查集

    #include<iostream> #include<cstring> using namespace std; ; int d[N],p[N]; int find(int ...

  5. sqli-labs less-17 --> less-20

    Less-17 (报错盲注) 参考资料1:https://www.cnblogs.com/AmoBlogs/p/8673748.html

  6. H5_0012:js事件冒泡和捕获

    捕获(capture)和冒泡(bubble)是事件传播过程中的两个概念, 比如用户单击某个元素, 但由于元素处于父元素内, 该父元素又处于document对象中, document对象又处于windo ...

  7. C++野指针的存在方式和误区

    1. char* x;这样的一定是野指针,指针声明时要直接初始化!或者置null也行! 2. int main() { char *x=new char; delete x; cout<< ...

  8. PDF体检报告

    //Title: 个人健康管理分析报告 using System; using System.Collections.Generic; using System.Linq; using System. ...

  9. Dart单例模式最佳实践

    /// Created by Capt. Michael @ CaptNotes.com on 02/17/2020. class Singleton { Singleton._(); static ...

  10. 前端面试必备技巧(二)css盒模型及BFC

    CSS盒模型 基本概念:标准模型+IE模型及区别 CSS如何设置这两种模型? JS如何设置获取盒模型对应的宽和高? 实例题(根据盒模型解释边距重叠) BFC边距重叠解决方案 (1)BFC的基本概念:b ...