本文主要是介绍总结购物车小程序知识点,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
购物车小程序:
知识点:
1. input()函数,while循环, if...elseif...else语句,for循环
2. 字符串方法 .isdigit()和.center()
3. 枚举 enumerate()
4. 列表切片与列表方法追加.append()
5. 词典的使用
6. 字符串格式化输出
#! /usr/bin/env python3
# -*- coding:UTF-8 -*-
# Author:F.Wsalary = input("input your salary:")
if salary.isdigit():salary = int(salary) 输入的字符串如果是数字,强制转换为整型,方便后续比较大小
else:exit("invalid data type!") 输入如果不符合要求,提示退出程序
Welcome_msg = "Welcome to FAN shopping mall".center(50, '-')
print(Welcome_msg)exit_flag = False
Product_List = [('iphone', 5000), ('bike', 700), ('cloth', 300), ('basketball', 150)]
Shopping_car = []
while not exit_flag:print('Product_List'.center(50, '-'))for item in enumerate(Product_List):index = item[0] 切片获得商品序
这篇关于总结购物车小程序知识点的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!