簡易ショッピング機能の実現
4207 ワード
#! /usr/bin/env python
#coding: utf-8
#file: market.py
#Author: toddlerya
#date: 11-28-2014
#version: 1.0
""""
:
1、 , !
2、 , , !
3、 , ( )
4、 ,
5、 , ; ,
6、 ,
"""
objects = ['coffee','car','mobile','Internet','clothes']
prices = [35,30000,3000,6000,500]
shop_list = []
name = "jojo"
passwd = "bean"
choose = ""
choice = ""
def login():
while True:
name = raw_input("please input your name:")
if name == "jojo":
password = raw_input("please input your password:")
while password != 'bean':
password = raw_input("please input your password:")
print "----------------------------------"
print "welcome to login to system!
"
print "----------------------------------"
break
else:
print "+-----------------------------+"
print "user %s not found,try again!" % name
print "+-----------------------------+"
continue
def recharge():
global self_sal
self_sal = (raw_input("please store your money: "))
while not self_sal.isdigit():
self_sal = raw_input('not a number, please try again: ')
self_sal = int(self_sal)
while True:
if self_sal > 0:
print '
--------------------------------------'
print 'you had stored %s successfully!
' % self_sal
break
else :
print '---------------------------------'
self_sal = int(raw_input("you store money failure,
please store money again:"))
continue
def shop():
purchase = raw_input('Do you want to shop(yes/no):%s' % choose)
if purchase == 'yes':
for i in objects:
print i,'\t',prices[objects.index(i)]
elif purchase == 'no':
print '
------------------------------------'
print 'you had exited system successfully!'
print '----------------------------------'
global choice
choice = "!!!"
F_choice = choice.strip()
login()
recharge()
shop()
while choice != "!!!":
choice = raw_input("Please input one item to buy(input '!!!' to quit): ")
F_choice = choice.strip()
if F_choice == "!!!":
break
if F_choice in objects:
objects_index = objects.index(F_choice)
objects_price = prices[objects_index]
print F_choice,'---->',objects_price
if self_sal > objects_price:
shop_list.append(F_choice)
print 'Added %s into shop list' % choice
self_sal = self_sal - objects_price
print "Salary left:",self_sal
choice = ""
continue
else:
if self_sal < min(prices):
print 'Sorry,rest of your salary cannot buy anything!88'
print "you hava bought these things: %s" % shop_list
break
else:
print "Sorry,you cannot afford this product,please try other ones!
"
print "-----------------------------------------------------------------"
choice = raw_input("please input one item to buy(input '!!!' to quit):")
F_choice = choice.strip()
continue
else:
print "Not such products!Please input one item to buy again!(input '!!!' to quit):"
print "-------------------------------------------------------"
choice = raw_input("please input one item to buy(input '!!!' to quit):")
F_choice = choice.strip()
continue