(一)循环
(1)循环的介绍
循环语句用于多次、重复性地执行一组语句,其控制结构图如下:

(2)while循环
1) while循环语句的一般形式
while condition:statement
下面的while循环实现了计算从1到100的和
sum = 0i = 0while i < 100:i += 1sum += iprint("从1到{:d}的和为{:d}".format(i, sum))
运行结果为:
从1到100的和为5050
2)无限while循环
无限循环,意味着while语句的condition永远为true,循环不会结束
例如:
while 1 == 1 :statementi = 1while i > 0 :statement
通常,这种循环用于处理客户端的实时请求,例如:
#在屏幕显示菜单,当用户做出选择后输出用户的输出信息,然后回车后返回菜单继续while 1==1:print("{:^200} \n".format("Menu List"))print("{:<200}\n".format("我们向您提供以下各种口味的奶茶:"))print("{:<200}\n".format("1.原味冰奶茶,每杯3元"))print("{:<200}\n".format("2.香蕉冰奶茶,每杯5元"))print("{:<200}\n".format("3.草莓冰奶茶,每杯5元"))print("{:<200}\n".format("4.蒟蒻冰奶茶,每杯7元"))print("{:<200}\n".format("5.珍珠冰奶茶,每杯7元"))choice=input("请输入数字1-5来选择对应的你喜欢的口味(1-5):")print("你选择了%s号奶茶" % choice)input("按任意键回车后返回菜单")
3)while…else语句
while…else用于实现循环的分支控制,即:当条件成立,为True的时候,执行while循环体中的语句,反之,执行else循环体中的语句
其形式如下:
while condition :statement1else :statement2
例如:
sum = 0i = 0while i<100 :i += 1sum += ielse:print("Calculation finnished, the result is {:d}".format(sum))
运行结果为:
Calculation finnished, the result is 5050
(3)for循环
for语句在Python当中非常重要,在遍历序列项目的应用中非常广泛
其一般形式为:
for <variable> in <sequence>:<statements>else:<statements>
使用for语句遍历元组
tu1 = ("do","what","done","be")i = 0for item in tu1 :i += 1print("ITEM %d is: %s" % (i,item))
运行结果为:
ITEM 1 is: doITEM 2 is: whatITEM 3 is: doneITEM 4 is: be
使用for语句遍历列表
list1 = ["To","be","or","not","to","be,","that's","a","question!"]for item in list1:print("{} ".format(item),end="")
运行结果为:
To be or not to be, that's a question!
使用for语句遍历字典
dict1 = {"start_point":"116,89","end_point":"89","distance":"110.98","direction":"Northeast"}for key in dict1:print(dict1[key])
运行结果为:
116,8989110.98Northeast
(4)range函数
range函数往往和for语句配合使用,用于对数字序列的遍历
例如:
#类似于c语言中的for(i=0;i<=9;i++)for i in range(10) :print("i=%d" % i )
运行结果为:
i=0i=1i=2i=3i=4i=5i=6i=7i=8i=9
range函数也可以指定生成数字序列的初值和终值,以及步长
例如:
#指定初值和终值(初值包含,终值不包含,步长为1)for i in range(5,10) :print("i=%d" % i )print("-----------------------")#指定初值,终值,步长为1for i in range(3,11,2):print("i=%d" % i)print("########################")#初值、终值和步长都可以为负数for i in range(11, 2, -3):print("i=%d" % i)
结果为:
i=5i=6i=7i=8i=9-----------------------i=3i=5i=7i=9########################i=11i=8i=5
上课例题:打印一个图案
for i in range(0,4):print(' '*i,end="")print("*"*(7-2*i))for i in range(2,-1,-1):print(' '*i,end="")print("*"*(7-2*i))
运行可得:
*******************************
(5)len()函数
len()函数用于返回一个序列的长度,例如元组、列表或者字典等
例如:
tu1 = ("do","what","done","be")list1 = ["To","be","or","not","to","be,","that's","a","question!"]dict1 = {"start_point":"116,89","end_point":"89","distance":"110.98","direction":"Northeast"}#打印元组,列表和字典的长度print("%d,%d,%d" % (len(tu1), len(list1), len(dict1)))
结果为:
4,9,4
(6)range和len结合以遍历一个序列
例如:
print("----------list---------")list1 = ["To","be","or","not","to","be,","that's","a","question!"]#利用range配合len函数来生成列表的索引序列,并逐一打印索引下标和列表各个元素for i in range(len(list1)) :print("i=%d,item=%s" % (i,list1[i]))print("----------tuple----------")tu1 = ("do","what","done","be")#利用range配合len函数来生成元组的索引序列,并逐一打印索引下标和元组for i in range(len(tu1)):print("i=%d,item=%s" % (i,tu1[i]))
----------list---------i=0,item=Toi=1,item=bei=2,item=ori=3,item=noti=4,item=toi=5,item=be,i=6,item=that'si=7,item=ai=8,item=question!----------tuple---------i=0,item=doi=1,item=whati=2,item=donei=3,item=be
(7) break语句
break语句用于跳出for或者while循环体。当使用break的时候,将从对应的循环体跳出
例如:
s1="No pain"s2="No gain"#对s1,s2字符串进行合并,然后取出逐个字母for letter in s1+" "+s2 :print(letter, end="")#判断,如果当前字母为o,则退出循环if letter == 'o':break
结果为
No
如果是多重循环,则只退出break语句所在的循环体,并不退出外重循环,例如
# i负责直角三角形个数,j负责直角三角形的行数。由于在内层循环中使用了break,则只打印了五行,但是break不会导致退出外层循环,因而直角三角形个数仍然是3个。for i in range(0,3):print("-"*(2*i),end="")for j in range(0,10):print("*"*j)if j==5 :break
运行结果为
***************--***************----***************
(8)continue
continue可以使得当前循环语句块中剩余未执行的语句被跳过,继续进行下一轮循环
例如:
s1="No pain"s2="No gain"#s1、s2合并之后,判断如果当前字母为o,则不打印,进行下一轮循环for letter in s1+" "+s2 :if letter == 'o':continueprint(letter, end="")
运行结果为:
N pain N gain
(9) pass
pass是个空语句,什么都不做,只是为了占位,防止语法错误
(二)字符串
(1)定义
字符串是Python中常见的数据类型,创建字符串,只需要以如下变量赋值形式创建即可
变量名="字符串"例如:s1 = "Work hard"
(2)引用
Python中引用字符串,可以使用索引值的形式,例如:
#索引序列从0开始排序,左闭右开s1 = "No Pain No gain!"print("s1=%s" % s1[1:5])#初值缺省,默认为0print("s1=%s" % s1[:5])#终值缺省,默认为最后一个字符print("s1=%s" % s1[6:])#第三个值为步长,步长可以为负值print("s1=%s" % s1[6:2:-1])#初值、终值也可以为负值,负值意味着从右边第一个字符开始数,-1开始以此类推print("s1=%s" % s1[-2:-6:-1])#终值省略,且步长为负数,则默认终值为第一个字符位置print("s1=%s" % s1[-2::-2])#终值省略,且步长为正数,则默认终值为最后一个字符位置print("s1=%s" % s1[-2::2])#初值,终值都省略,步长为1,则为倒序输出字符串print("s1=%s" % s1[::-1])
运行结果为
s1=o Pas1=No Pas1=n No gain!s1=niaPs1=niags1=na Nna Ns1=ns1=!niag oN niaP oN
(3)字符串运算
1)运算符
- 字符串连接
- 重复输出字符串
- in 判断是否包含指定子串
- not in 判断是否不包含指定子串
- r/R 原始字符输出,不当做转义字符对待
2)举例
#判断s2是否包含s1,是则输出"Miao",否则输出"Wang"s1 = "Hello"s2 = "Hello kitty"if s1 in s2 :print("Miao")else:print("Wang")
运行结果为:
Miao
再者:
#如果以r开头,则\n原样输出,不作处理,否则是换行的转义符print(r'a\n')print('a\n')#以R开头,则\t原样输出,不作处理print(R'a\tb')print('a\tb')
运行结果为:
a\naa\tba b
(三)列表
(1)列表的创建
列表是python中最基本的数据结构,序列中的每个元素都分配一个数字,从0开始依次排序,可以称之为索引值
创建一个列表,可以采用如下形式:
列表名称= [列表项1,列表项2,列表项3...]例如:list1 = ["我们","爱","科学"]list2 = [1,2,3,4,5]
(2)列表值的引用
类似于字符串,列表中值也可以通过列表名[索引值]的形式加以引用,以下是几个例子
list1 = ["People", "sir,", "we", "should", "let", "them", "know!"]list2 = ["It", "will", "take", "more", "than", "that"]#序列从0开始,左闭右开print("list1=%s" % list1[1:5])#初值缺省默认为0print("list1=%s" % list1[:5])#终值缺省默认为最后的位置print("list1=%s" % list1[3:])#步长可以为负数print("list1=%s" % list1[6:2:-1])#初值、终值也可以为负数,意味着从最后倒数,-1开始print("list1=%s" % list1[-2:-6:-1])#步长为负数,且终值缺省,则终值默认为起始位置print("list1=%s" % list1[-2::-2])#步长为证书,且终值缺省,则默认终值为最后位置print("list1=%s" % list1[-2::2])#步长为-1,且初值、终值均缺省,则为倒序输出print("list1=%s" % list1[::-1])
运行结果为:
list1=['sir,', 'we', 'should', 'let']list1=['People', 'sir,', 'we', 'should', 'let']list1=['should', 'let', 'them', 'know!']list1=['know!', 'them', 'let', 'should']list1=['them', 'let', 'should', 'we']list1=['them', 'should', 'sir,']list1=['them']list1=['know!', 'them', 'let', 'should', 'we', 'sir,', 'People']
(3)Python列表的运算
类似于字符串,Python列表同样也可以使用运算符进行运算
1)运算符
- len() 返回列表的长度
- 拼接两个列表
- 重复列表
- in 判断元素是否在列表中,或者用于对列表序列进行迭代
- max()返回列表的最大值
- min()返回列表的最小值
- list()将元组转换为列表
2)举例
list1 = ["People", "sir,", "we", "should", "let", "them", "know!"]list2 = ["It", "will", "take", "more", "than", "that"]#使用len()测量长度,并打印print("length of list:%d" % len(list1))print("length of list ['a',1,3+4j] is: {:d}".format(len(['a',1,3+4j])))#两个列表合并为一个,并打印list_a = list1 + list2print("list_a=%s" % list_a)#判断元素是否在列表中,并打印list3 = ["what"]list4 = ["what", "is", "it"]if list3[0] in list4:print("Done")else:print("Wrong")#将list1列表扩大为三倍原来元素的列表print(list1*3)
结果为:
length of list:7length of list ['a',1,3+4j] is: 3list_a=['People', 'sir,', 'we', 'should', 'let', 'them', 'know!', 'It', 'will', 'take', 'more', 'than', 'that']Done['People', 'sir,', 'we', 'should', 'let', 'them', 'know!', 'People', 'sir,', 'we', 'should', 'let', 'them', 'know!', 'People', 'sir,', 'we', 'should', 'let', 'them', 'know!', 'People', 'sir,', 'we', 'should', 'let', 'them', 'know!']
再看一个关于最大值和最小值的例子:
list1 = ["People", "sir,", "we", "should", "let", "them", "know!"]list2 = ["It", "will", "take", "more", "than", "that"]print("maximal item of list is: %s" % max(list1))print("Minimal item of list is: %s" % min(list1))
运行结果为
maximal item of list is: weMinimal item of list is: People
(4)列表值的添加、修改和删除
1)列表值的添加
(i)append方法
在末尾添加新的值可以使用内置的append方法,例如:
list1 = ["People", "sir,", "we", "should", "let", "them", "know!"]list2 = ["It", "will", "take", "more", "than", "that"]#list1增加一项list1.append("Warning")print("list1=%s" % list1)#list2增加一项list2.append(" !")print("list2={}".format(list2))#list1增加一项为列表,形成嵌套列表list1.append(["Maybe","it","is"])print("list1={}".format(list1))
运行结果为:
list1=['People', 'sir,', 'we', 'should', 'let', 'them', 'know!', 'Warning']list2=['It', 'will', 'take', 'more', 'than', 'that', ' !']list1=['People', 'sir,', 'we', 'should', 'let', 'them', 'know!', 'Warning', ['Maybe', 'it', 'is']]
(ii)extend方法
使用extend方法,可以把一个整的序列转换为被操作列表的各个项,这点不同于append,append是将整个序列作为一个元素附加到原列表的后面。
例如:
list1 = ["People", "sir,", "we", "should", "let", "them", "know!"]list2 = ["It", "will", "take", "more", "than", "that"]#注意,这时候extend附加的是一个字符串"Warning",而字符串会被视作一个序列,拆分成单个字符list1.extend("Warning")print("list1=%s" % list1)#如果指定附加的是一个列表,则指定列表中的每一项都会被附加到原来列表后面,成为一个新的项list1.extend(["regard"])print("list1=%s" % list1)#同理,空格和惊叹号都会被拆开list2.extend(" !")print("list2={}".format(list2))#列表中的每一个项会被拼接到原列表后面list1.extend(["Maybe","it","is"])print("list1={}".format(list1))
运行结果为:
list1=['People', 'sir,', 'we', 'should', 'let', 'them', 'know!', 'W', 'a', 'r', 'n', 'i', 'n', 'g']list1=['People', 'sir,', 'we', 'should', 'let', 'them', 'know!', 'W', 'a', 'r', 'n', 'i', 'n', 'g', 'regard']list2=['It', 'will', 'take', 'more', 'than', 'that', ' ', '!']list1=['People', 'sir,', 'we', 'should', 'let', 'them', 'know!', 'W', 'a', 'r', 'n', 'i', 'n', 'g', 'regard', 'Maybe', 'it', 'is']
(iii)insert方法
insert方法可以将特定值插入到指定列表中的指定位置,其格式如下:
list.insert(index,obj)
举例如下:
#在指定位置插入"not",此时not作为一个整体插入到了指定位置,而原来的元素依次后退list3=["He","always","holds","charming","for","little","girls"]list3.insert(2, "not")print("list3={}".format(list3))#同样,如果我们指定插入一个列表,则指定列表会作为一个整体插入到对应的位置,形成嵌套列表,而不像extend,会对列表进行打散的处理list4=["Love", "me,", "love", "my", "dog"]list4.insert(1, ["baby", "not"])print("list4={}".format(list4))
运行结果如下:
list3=['He', 'always', 'not', 'holds', 'charming', 'for', 'little', 'girls']list4=['Love', ['baby', 'not'], 'me,', 'love', 'my', 'dog']
2)列表项的修改
举例:
list1=[1,3,5,7,9]#修改列表第一个元素的值为100list1[0]=100#修改列表最后一个元素的值为200list1[-1]=200print("list1={}".format(list1))
运行结果为:
list1=[100, 3, 5, 7, 200]
3)列表项删除
(i)del函数删除
格式:del 列表项
如:
list5 = ["Where", "there's", "a", "will,", "there", "is", "a", "way"]del(list5[1])print("list5={}".format(list5))#删除倒数第一个、第二个元素,如果不指定步长,默认为1del(list5[-1:-3:-1])print("list5={}".format(list5))
运行结果为:
list5=['Where', 'a', 'will,', 'there', 'is', 'a', 'way']list5=['Where', 'a', 'will,', 'there', 'is']
(ii)pop方法
list.pop方法用于移除列表中的一个元素(默认为最后一个元素),并返回该元素的值
格式: list.pop(obj=list[-1])
例如:
#没有指定索引序列号,则默认为移除最后一个字符list6 = ["Marriage", "is", "a", "lottery"]get_last_item = list6.pop()print("list6={}".format(list6))print("Get_last_item={}".format(get_last_item))#指定索引序列号,则移除指定的项目,并将此项目的值作为函数的返回值返回list7 = ["There", "is", "no", "accounting", "for", "tastes"]print("list7.pop(3)={}".format(list7.pop(3)))print("list7={}".format(list7))
运行结果为:
list6=['Marriage', 'is', 'a']Get_last_item=lotterylist7.pop(3)=accountinglist7=['There', 'is', 'no', 'for', 'tastes']
(iii)remove方法
remove方法需要指定值,本方法可以移除列表中指定值的第一个匹配项
例如:
#两个“sooner”,第一个被remove方法删掉了list8=["The", "sooner", "begun,", "the", "sooner", "done"]list8.remove("sooner")print("list8={}".format(list8))
结果为:
list8=['The', 'begun,', 'the', 'sooner', 'done']
(IV)clear方法
clear方法用于清空列表,很方便
例如:
list9=["They", "will", "all", "be", "wiped", "out", "from", "the", "Earth"]print("list9={}".format(list9))list9.clear()print("list9={}".format(list9))
结果为
list9=['They', 'will', 'all', 'be', 'wiped', 'out', 'from', 'the', 'Earth']list9=[]
(5)Python列表的统计、排序、复制和查找
1)python列表的复制
(i)copy内置方法
#注意:类似list10=list9之类的复制是无效的,这么定义,只是定义了一个指向list9的指针list10list9=["They", "will", "all", "be", "wiped", "out", "from", "the", "Earth"]print("list9={}".format(list9))list10=list9.copy()list9.clear()print("list9={}".format(list9))print("list10={}".format(list10))
运行结果为:
list9=['They', 'will', 'all', 'be', 'wiped', 'out', 'from', 'the', 'Earth']list9=[]list10=['They', 'will', 'all', 'be', 'wiped', 'out', 'from', 'the', 'Earth']
(ii)list[:]格式的复制
list9=["They", "will", "all", "be", "wiped", "out", "from", "the", "Earth"]print("list9={}".format(list9))list10=list9[:]list9.clear()print("list9={}".format(list9))print("list10={}".format(list10))
运行结果为:
list9=['They', 'will', 'all', 'be', 'wiped', 'out', 'from', 'the', 'Earth']list9=[]list10=['They', 'will', 'all', 'be', 'wiped', 'out', 'from', 'the', 'Earth']
2)排序和倒序
(i)sort方法排序
例如:
list11=[0,8,6,23,33,89,12,255,7]list11.sort()print("list11={}".format(list11))#reverse=True为降序排列list11.sort(reverse=True)print("list11={}".format(list11))
结果为:
list11=[0, 6, 7, 8, 12, 23, 33, 89, 255]list11=[255, 89, 33, 23, 12, 8, 7, 6, 0]
(ii)reverse倒序输出
例如:
list11=[0,8,6,23,33,89,12,255,7]list11.reverse()print("list11={}".format(list11))
结果为:
list11=[7, 255, 12, 89, 33, 23, 6, 8, 0]
3) count()计数
count方法用于统计某个元素在列表中的出现个数
例如:
list12=["to", "to", "be", "or", "not", "to", "be"]#输出"be"在list12中出现的次数print(list12.count("be"))#输出"to"在list12中出现的次数print(list12.count("to"))
结果为:
23
4)index()查找位置的方法
index方法用于从列表中找到指定值的第一个匹配项的索引序号
例如:
list9=["They", "will", "all", "be", "wiped", "out", "from", "the", "Earth"]print(list9.index("all"))
运行结果为
2
(四)作业
(1)代码
# 初始化价格字典price={"原味冰奶茶":3,"香蕉冰奶茶":5,"草莓冰奶茶":5,"蒟蒻冰奶茶":7,"珍珠冰奶茶":7}# 初始化营业次数计数器count = 0# 初始化消费情况列表consumption_list = []# 初始化会员列表membership_list = []# 开始循环打印菜单while 1 == 1:flag = 0member_id = "Not VIP"print("{:^200} \n".format("Menu List"))print("{:<200}\n".format("我们向您提供以下各种口味的奶茶:"))print("{:<200}\n".format("1.原味冰奶茶,每杯3元"))print("{:<200}\n".format("2.香蕉冰奶茶,每杯5元"))print("{:<200}\n".format("3.草莓冰奶茶,每杯5元"))print("{:<200}\n".format("4.蒟蒻冰奶茶,每杯7元"))print("{:<200}\n".format("5.珍珠冰奶茶,每杯7元"))# 输入选择的口味choice=input("请输入数字1-5来选择对应的你喜欢的口味(1-5):")key_list=["1","2","3","4","5"]if choice not in key_list:print("Woops! 我们只售卖以上五种奶茶哦!新口味敬请期待!现在返回菜单!")continue# 输入选择的数量quantity=input("请输入你需要的数量(1-10):")quantity_list=["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]membercard_digit_list = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]if quantity not in quantity_list:print("数量输入错误,返回菜单")continue#输入VIP身份VIP=input("你是VIP顾客吗?(Y/N):")VIP_list=["y","n","Y","N"]if VIP not in VIP_list:print("VIP身份输入错误,返回菜单")continuediscount=1identifier="不是"reduce = "未能享受"# 如果是VIP客户,要求输入五位会员卡号码,输入长度不是五位,或者不是纯数字,都将报错返回主菜单if VIP in ["Y","y"]:identifier = "是"member_id = input("请输入您的五位会员卡号码:")tmp = []tmp.extend(member_id)if len(tmp) != 5:print("会员卡号长度非法,返回菜单")continuefor ch in tmp:if ch not in membercard_digit_list:print("会员卡号含非法字符,返回菜单")flag = 1breakif flag == 1:continueif member_id not in membership_list:membership_list.append(member_id)else:discount = 0.9reduce = "享受了"#根据选择确定的对应的口味if choice=="1":key="原味冰奶茶"elif choice=="2":key="香蕉冰奶茶"elif choice=="3":key="草莓冰奶茶"elif choice=="4":key="蒟蒻冰奶茶"else:key="珍珠冰奶茶"# 营业次数加1count += 1# 计算应付总价total_payment=price[key]*int(quantity)*discount# 将本次消费情况记入列表consumption_list.append({"id":count, "member_id":member_id, "taste":key, "quantity":quantity, "price":price[key], "discount":discount, "total_payment":total_payment})# 打印最终的总价计算信息以及相关信息print("欢迎您,您是今天光临本店的第%d位客人" % count)print("您选择了{:5},单价为{:d}元,数量为{:2d}杯,您{}VIP用户,您{}九折优惠价".format(key,price[key],int(quantity),identifier,reduce))print("应付总价为:{:<10.2f}元".format(total_payment))# 为了便于观察,这里在每次成功售卖奶茶之后,都会打印出历史消费情况for item in consumption_list:print(item)input("请输入回车继续")# 本日营业满20次,则退出系统if count >= 20:print("今日已经闭店,欢迎您明天光临!")break
(2)运行结果
调试运行的时候,为了方便起见,仅将日营业次数设置为了4
Menu List我们向您提供以下各种口味的奶茶:1.原味冰奶茶,每杯3元2.香蕉冰奶茶,每杯5元3.草莓冰奶茶,每杯5元4.蒟蒻冰奶茶,每杯7元5.珍珠冰奶茶,每杯7元请输入数字1-5来选择对应的你喜欢的口味(1-5):1请输入你需要的数量(1-10):2你是VIP顾客吗?(Y/N):Y请输入您的五位会员卡号码:00021欢迎您,您是今天光临本店的第1位客人您选择了原味冰奶茶,单价为3元,数量为 2杯,您是VIP用户,您未能享受九折优惠价应付总价为:6.00 元{'id': 1, 'member_id': '00021', 'taste': '原味冰奶茶', 'quantity': '2', 'price': 3, 'discount': 1, 'total_payment': 6}请输入回车继续Menu List我们向您提供以下各种口味的奶茶:1.原味冰奶茶,每杯3元2.香蕉冰奶茶,每杯5元3.草莓冰奶茶,每杯5元4.蒟蒻冰奶茶,每杯7元5.珍珠冰奶茶,每杯7元请输入数字1-5来选择对应的你喜欢的口味(1-5):1请输入你需要的数量(1-10):3你是VIP顾客吗?(Y/N):Y请输入您的五位会员卡号码:00021欢迎您,您是今天光临本店的第2位客人您选择了原味冰奶茶,单价为3元,数量为 3杯,您是VIP用户,您享受了九折优惠价应付总价为:8.10 元{'id': 1, 'member_id': '00021', 'taste': '原味冰奶茶', 'quantity': '2', 'price': 3, 'discount': 1, 'total_payment': 6}{'id': 2, 'member_id': '00021', 'taste': '原味冰奶茶', 'quantity': '3', 'price': 3, 'discount': 0.9, 'total_payment': 8.1}请输入回车继续Menu List我们向您提供以下各种口味的奶茶:1.原味冰奶茶,每杯3元2.香蕉冰奶茶,每杯5元3.草莓冰奶茶,每杯5元4.蒟蒻冰奶茶,每杯7元5.珍珠冰奶茶,每杯7元请输入数字1-5来选择对应的你喜欢的口味(1-5):1请输入你需要的数量(1-10):5你是VIP顾客吗?(Y/N):Y请输入您的五位会员卡号码:00021欢迎您,您是今天光临本店的第3位客人您选择了原味冰奶茶,单价为3元,数量为 5杯,您是VIP用户,您享受了九折优惠价应付总价为:13.50 元{'id': 1, 'member_id': '00021', 'taste': '原味冰奶茶', 'quantity': '2', 'price': 3, 'discount': 1, 'total_payment': 6}{'id': 2, 'member_id': '00021', 'taste': '原味冰奶茶', 'quantity': '3', 'price': 3, 'discount': 0.9, 'total_payment': 8.1}{'id': 3, 'member_id': '00021', 'taste': '原味冰奶茶', 'quantity': '5', 'price': 3, 'discount': 0.9, 'total_payment': 13.5}请输入回车继续Menu List我们向您提供以下各种口味的奶茶:1.原味冰奶茶,每杯3元2.香蕉冰奶茶,每杯5元3.草莓冰奶茶,每杯5元4.蒟蒻冰奶茶,每杯7元5.珍珠冰奶茶,每杯7元请输入数字1-5来选择对应的你喜欢的口味(1-5):1请输入你需要的数量(1-10):2你是VIP顾客吗?(Y/N):Y请输入您的五位会员卡号码:890987会员卡号长度非法,返回菜单Menu List我们向您提供以下各种口味的奶茶:1.原味冰奶茶,每杯3元2.香蕉冰奶茶,每杯5元3.草莓冰奶茶,每杯5元4.蒟蒻冰奶茶,每杯7元5.珍珠冰奶茶,每杯7元请输入数字1-5来选择对应的你喜欢的口味(1-5):1请输入你需要的数量(1-10):5你是VIP顾客吗?(Y/N):0iuysVIP身份输入错误,返回菜单Menu List我们向您提供以下各种口味的奶茶:1.原味冰奶茶,每杯3元2.香蕉冰奶茶,每杯5元3.草莓冰奶茶,每杯5元4.蒟蒻冰奶茶,每杯7元5.珍珠冰奶茶,每杯7元请输入数字1-5来选择对应的你喜欢的口味(1-5):5请输入你需要的数量(1-10):10你是VIP顾客吗?(Y/N):Y请输入您的五位会员卡号码:00022欢迎您,您是今天光临本店的第4位客人您选择了珍珠冰奶茶,单价为7元,数量为10杯,您是VIP用户,您未能享受九折优惠价应付总价为:70.00 元{'id': 1, 'member_id': '00021', 'taste': '原味冰奶茶', 'quantity': '2', 'price': 3, 'discount': 1, 'total_payment': 6}{'id': 2, 'member_id': '00021', 'taste': '原味冰奶茶', 'quantity': '3', 'price': 3, 'discount': 0.9, 'total_payment': 8.1}{'id': 3, 'member_id': '00021', 'taste': '原味冰奶茶', 'quantity': '5', 'price': 3, 'discount': 0.9, 'total_payment': 13.5}{'id': 4, 'member_id': '00022', 'taste': '珍珠冰奶茶', 'quantity': '10', 'price': 7, 'discount': 1, 'total_payment': 70}请输入回车继续今日已经闭店,欢迎您明天光临!
