找回密码
 中文实名注册
搜索
楼主: admin

【Python作业】第四单元 第4课 黄金矿工 全局变量

[复制链接]

3

主题

27

回帖

660

积分

高级会员

积分
660
发表于 2022-1-22 11:39:43 | 显示全部楼层

回帖奖励 +40 金钱

import random


total = 0


def cal():
    global total
    box = random.choice(['石头','黄金','钻石'])
    if box == '石头':
        total = total + 20
    elif box == '黄金':
        total = total + 100
    else:
        total = total + 500


cal()
print(total)
回复

使用道具 举报

2

主题

19

回帖

833

积分

高级会员

积分
833
发表于 2022-1-22 11:35:46 | 显示全部楼层

回帖奖励 +40 金钱

import random


total = 0


def cal():
    global total
    box = random.choice(['石头', '黄金', '钻石'])
    if box == '石头':
        total = total+20
    elif box == '黄金':
        total = total+100
    else:
        total = total+500

cal()
print(total)
回复

使用道具 举报

3

主题

38

回帖

827

积分

高级会员

积分
827
发表于 2022-1-22 11:35:14 | 显示全部楼层

回帖奖励 +40 金钱

本帖最后由 陈晓帅 于 2022-1-22 11:49 编辑

import random

total = 0


def cal():
global total
box = random.choice(['石头','黄金','钻石'])
if box == '石头':
total = total + 20
elif box == '黄金':
total = total + 200
else:
total = total + 500

论坛我最帅
回复

使用道具 举报

0

主题

23

回帖

-161

积分

限制会员

积分
-161
发表于 2022-1-22 11:34:35 | 显示全部楼层

回帖奖励 +40 金钱

import random
total = 0

def cal():
    global total
    box = random,choicore = (['石头','黄金','钻石'])
    if box == '石头':
        total = total + 20
    elif box == '黄金'
        total == total + 100
    elif:
        total = total + 500
cal()
print(total)
回复

使用道具 举报

1

主题

12

回帖

1331

积分

金牌会员

积分
1331
发表于 2022-1-9 15:28:31 | 显示全部楼层

回帖奖励 +40 金钱

import random
a=random.randint(1,100000000000)
while True:
    g=input('输入1到10000000000000的一个数')
    g=int(g)
    if g>a:
        print('大')
    elif g<a:
            print('小')
    else:
        print('对')
        break
回复

使用道具 举报

1

主题

34

回帖

1154

积分

版主

积分
1154
发表于 2022-1-9 15:26:00 | 显示全部楼层

回帖奖励 +40 金钱

import random
a=random.randint(1,100000000000)
while True:
    g=input('输入1到10000000000000的一个数')
    g=int(g)
    if g>a:
        print('大')
    elif g<a:
            print('小')
    else:
        print('对')
        break
回复

使用道具 举报

3

主题

48

回帖

3628

积分

论坛元老

积分
3628
发表于 2022-1-9 10:21:45 | 显示全部楼层

回帖奖励 +40 金钱

[Python] 纯文本查看 复制代码
import random
total = 0
def cal():
    global total
    box = random.choice(['石头','黄金','钻石'])
    if box == '石头':
        total = total + 20
    elif box == '黄金':
        total = total + 100
    else:
        total = total + 500
cal()
print(total)
回复

使用道具 举报

15

主题

48

回帖

-158

积分

版主

你爸爸

积分
-158
发表于 2022-1-9 10:19:00 | 显示全部楼层

回帖奖励 +40 金钱

本帖最后由 曹帅 于 2022-1-23 09:42 编辑

import random
total=0
def cal()
    global total
    box = random.choice(['石头', '黄金','钻石', '炸弹'])
    if box == '石头':
        total = total + 20
    elif box == '黄金':
        total = total + 100    elif box == '炸弹'
        total = total -20
    else:
        total = total + 500

cal()
print(total)

回复

使用道具 举报

3

主题

69

回帖

78

积分

版主

积分
78
发表于 2022-1-9 10:15:20 | 显示全部楼层

回帖奖励 +40 金钱

import random
def cal():
    global total
    total = 0
    ore_list = ['石头','黄金','钻石'
    box = random.choice(ore_list)
    if box == '石头':
        total += 20
    elif box == '黄金':
        total += 100
    else:
        total += 500


cal()
print(total)

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 中文实名注册

本版积分规则

快速回复 返回顶部 返回列表