猫史档案馆


【Python作品分享】新的作品【作品秀】

用户:我的世界fBNl我的世界fBNl查看:0 回复:0 评论:0 创建时间:2020-12-02T21:41:28


【作品展示】

center_image

 

【作品介绍】

模拟股票

 

【作品源代码】

import random
import time


cc1 = 0
cc2 = 0
cc3 = 0
money = 10000
while True:
    one = random.randint(100, random.randint(1, 10000))
    two = random.randint(100, random.randint(5000, 15000))
    three = random.randint(100, random.randint(10000, 100000))
    print('你有', money, '元')
    you = input('1买股票---2卖股票---3查看市值:')
    if (you == '1'):
        print('今日市值: 1号股票:', one,'元', '2号股票:', two, '元', '3号股票:', three, '元')
        try:
            you = int(input('请数入股票号码:'))
            if (you == 1):
                you = int(input('买多少张:'))
                if (money < you * one):
                    print('钱不够')
                else:
                    cc1 += you
                    money -= (you * one)
            if (you == 2):
                you = int(input('买多少张:'))
                if (money < you * two):
                    print('钱不够')
                else:
                    cc2 += you
                    money -= (you * two)
            if (you == 3):
                you = int(input('买多少张:'))
                if (money < you * three):
                    print('钱不够')
                else:
                    cc1 += you
                    money -= (you * three)
        except ValueError:
            print('不要输入符号或字!')
    elif you == '2':
        print('今日市值: 1号股票:', one, '元', '2号股票:', two, '元', '3号股票:', three, '元')
        try:
            you = int(input('卖几号股票:'))
            you_1 = you
            you = int(input('卖多少张:'))
            if you_1 == 1:
                cc1 -= you
                money += you*one
            if you_1 == 2:
                cc2 -= you
                money += you*two
            if you_1 == 3:
                cc3 -= you
                money += you*three
        except ValueError:
            print('不要输入符号或字!')
    else:
        print('今日市值: 1号股票:', one, '元', '2号股票:', two, '元', '3号股票:', three, '元')

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页