您的位置:首页 > 编程语言 > Python开发

python-列表练习程序ver1

2017-05-23 17:54 309 查看
列表练习

1、让用户输入工资

2、输出购物菜单及产品价格

3、计算用户是否可支付

4、输出用户剩余的钱,问用户是否继续购物,如果选择继续,继续进行,只到钱不够为止

5、如若不够,提示用户剩余工资不够购买,并推出程序

root@kali:~/python# cat listsalary.py

#!/usr/bin/python

# --*-- coding:utf-8 --*--

while True:

    salary = int(raw_input('please input your salary:')) #

    print '      -------shopping list---------'

    print '''

    old car        5000$

    iphone7s    799$

    knife        39$

    book        12$

    '''

    print '      -----------------------------'

    print 'your salary is % s$'% salary

    list1 = ['old car','5000']

    list2 = ['iphone7s','799']

    list3 = ['knife','39']

    list4 = ['book','12']

    select_number = 0

    print '-------------------------------------------------------------------------------------'                

        print 'you can buy %d old car,free_salary is %d$,please select 1' %(salary/5000,salary%5000)

    print 'you can buy %d iphone7s,free_salary is %d$,please select 2' %(salary/799,salary%799)

    print 'you can buy %d knife,free_salary is %d$,please select 3 ' %(salary/39,salary%39)

    print 'you can buy %d book,free_salary is %d$,please select 4' %(salary/12,salary%12)

    print '-------------------------------------------------------------------------------------'

    while True:

        select_number = int(raw_input('please select number:'))

        free_salary = 0

        if select_number == 1:

            print 'you buy %d old car '% int(free_salary/5000)

            print 'now your salary is %d$ '% int(free_salary%5000)

            free_salary = int(salary%5000)

            print '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'

            print 'now your free_salary is %d$,you can buy follow lists.'% free_salary

            print 'you can buy %d old car,free_salary is %d$,please select 1-4 exit!' %(free_salary/5000,free_salary%5000)

                   print 'you can buy %d iphone7s,free_salary is %d$,please select 1-4 exit!' %(free_salary/799,free_salary%799)

                print 'you can buy %d knife,free_salary is %d$,please select 1-4 exit! ' %(free_salary/39,free_salary%39)

                print 'you can buy %d book,free_salary is %d$,please select 1-4 exit!' %(free_salary/12,free_salary%12)

            print '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'

            select_number = int(raw_input('please select number:'))

            if free_salary <= 11:

                print 'you donot have salary ,you donot buy anything!'

                exit()

            if free_salary <=38 and free_salary>=12:

                print 'you can buy %d book ,please select 4' % int(free_salary/12)

                exit()

            if free_salary <=798 and free_salary>=38:

                print 'you can buy %d knife ,please select 3 ' % int(free_salary/39)

                exit()

            if free_salary <=4999 and free_salary>=799:

                print 'you can buy %d iphone7s ,please select 2' % int(free_salary/799)

                exit()

            if select_number == 2:

                    print 'you buy %d iphone7s '% int(free_salary/799)

                    print 'now your salary is %d$ '% int(free_salary%799)            

            free_salary = int(salary%799)

            print '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'

                        print 'now your free_salary is %d$,you can buy follow lists.'% free_salary

                        print 'you can buy %d iphone7s,free_salary is %d$,please select 1-4 exit!' %(free_salary/799,free_salary%799)

                        print 'you can buy %d knife,free_salary is %d$,please select 1-4 exit! ' %(free_salary/39,free_salary%39)

                        print 'you can buy %d book,free_salary is %d$,please select 1-4 exit!' %(free_salary/12,free_salary%12)

            print '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'

                        select_number = int(raw_input('please select number:'))

                        if free_salary <= 11:

                                print 'you donot have salary ,you donot buy anything!'

                                exit()

                        if free_salary <=38 and free_salary>=12:

                                print 'you can buy %d book ,please select 4' % int(free_salary/12)

                                exit()

            if free_salary <=798 and free_salary>=38:

                                print 'you can buy %d knife ,please select 3 ' % int(free_salary/39)

                                exit()

                if select_number == 3:

                    print 'you buy %d knife '% int(free_salary/39)

                    print 'now your salary is %d$ '% int(free_salary%39)

            free_salary = int(salary%39)

            print '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'

                        print 'now your free_salary is %d$,you can buy follow lists.'% free_salary

                           print 'you can buy %d knife,free_salary is %d$,please select 1-4 exit! ' %(free_salary/39,free_salary%39)

                        print 'you can buy %d book,free_salary is %d$,please select 1-4 exit!' %(free_salary/12,free_salary%12)

            print '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'

                        select_number = int(raw_input('please select number:'))

                        if free_salary <= 11:

                                print 'you donot have salary ,you donot buy anything!'

                                exit()

                        if free_salary <=38 and free_salary>=12:

                                print 'you can buy %d book ,please select 4' % int(free_salary/12)

                                exit()

                if select_number == 4:

                    print 'you buy %d book '% int(free_salary/12)

                    print 'now your salary is %d$ '% int(free_salary%12)

            free_salary = int(salary%12)

            print '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'

                        print 'now your free_salary is %d$,you can buy follow lists.'% free_salary

                           print 'you can buy %d book,free_salary is %d$,please select 1-4 exit!' %(free_salary/12,free_salary%12)

            print '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'

                        select_number = int(raw_input('please select number:'))

                        if free_salary <= 11:

                                print 'you donot have salary ,you donot buy anything!'

                                exit()

root@kali:~/python#
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: