python編程-購物車

import pymysql
db = pymysql.connect(host="192.168.146.209", user="root",password="123", db="pikachu", 		port=3306)
cur = db.cursor()
sql = "select * from pokemon3"
cur.execute(sql)
results = cur.fetchall()
total_money = 0
while True:
	print(results)
	goods = input('please select your goods(stop:0) : ')
	if goods == '1':
    	num = int(input('how many chips do you want : '))
    	total_money = total_money+num*10
    	print(total_money)
	elif goods == '2':
    	num = int(input('how many white_wine do you want : '))
    	total_money = total_money+num*20
    	print(total_money)
	elif goods == '3':
    	num = int(input('how many sugars do you want : '))
    	total_money = total_money+num*5
    	print(total_money)
	elif goods == '0':
    	break
while True:
	print(' ')
	print('you have custom %s'%(total_money))
	money = int(input('please enter your money : '))
	if money >= total_money:
    	print('still money:%s'%(money-total_money))
    	break
	else:
    	print('your money is not enough')

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章