python---購物

#!/usr/bin/env python     //程序開始
#Date: 2016-01-12

import sys

wide = 51
title = 'shop list'
none = (wide - len(title) - 2) // 2
Goods = ['Iphone','Quecao','LV','Trival','watch']
Prices = [5000,99,999,19999,3000]
print '*' * wide
print '*' * none + ' ' + title + ' ' + '*' * none
print Goods
print Prices
print '*' * wide     //打印列表單

Money = int(raw_input("Welcome, please input your wages: "))
if Money == 0:
        print "Your wages is %d, can't pay for anything!" %Money
elif Money > min(Prices):     //min(Prices)取得Prices中的最小值
        shop = raw_input("Please input what you want on the list:")
        if shop in Goods:
                print "Congratulations, you have got %s!" %shop
                pay_price = Prices[Goods.index(shop)]      //根據選擇內容查詢價格
                money_left = Money - pay_price     //餘額
                print "Your wage left: %s" %money_left
        else:
                print "Sorry, your choose not in list! You can try again!"
else:
        print "You have enough money, syetem will exit!"
        sys.exit()      //程序結束


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