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

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

[复制链接]

3

主题

21

回帖

1196

积分

金牌会员

积分
1196
QQ
发表于 2022-1-23 10:02:29 | 显示全部楼层

回帖奖励 +40 金钱

[Python] 纯文本查看 复制代码
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 - 200
    else:
        total = total +500


cal()
print(total)[color=Lime][/color]
回复

使用道具 举报

2

主题

27

回帖

823

积分

高级会员

积分
823
发表于 2022-1-23 10:01:53 | 显示全部楼层

回帖奖励 +40 金钱

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 - 200
    else:
        total = total + 500
cal()
print(total)
回复

使用道具 举报

2

主题

21

回帖

-172

积分

限制会员

积分
-172
发表于 2022-1-23 09:52:41 | 显示全部楼层

回帖奖励 +40 金钱

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 - 200
    else:
        total = total + 500
cal()
print(total)
回复

使用道具 举报

4

主题

60

回帖

2886

积分

金牌会员

积分
2886
发表于 2022-1-22 15:52:24 | 显示全部楼层

回帖奖励 +40 金钱


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 + 500
    else:
        total = total - 20
cal()
print(total)
回复

使用道具 举报

1

主题

14

回帖

-158

积分

限制会员

积分
-158
发表于 2022-1-22 15:24:41 | 显示全部楼层

回帖奖励 +40 金钱

import random


total = 0


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


cal()
print(total)
回复

使用道具 举报

0

主题

7

回帖

-153

积分

限制会员

积分
-153
发表于 2022-1-22 15:19:31 | 显示全部楼层

回帖奖励 +40 金钱

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+500
    else:
        total = total-100

cal()
print(total)
回复

使用道具 举报

2

主题

23

回帖

2043

积分

金牌会员

积分
2043
发表于 2022-1-22 15:15:44 | 显示全部楼层

回帖奖励 +40 金钱

import random
total = 0



def cal():
    global total
    s = ['石头', '黄金', '钻石', '狗骨头', '陈校长']
    box = random.choice(s)
    if box=='石头':
        total+=20
    elif box=='黄金':
        total+=100
    elif box =='钻石':
        total += 500
    elif box =='狗骨头':
        total -= 20
    else:
        total *= 2
    print(total)

回复

使用道具 举报

0

主题

26

回帖

1104

积分

金牌会员

积分
1104
发表于 2022-1-22 15:12:17 | 显示全部楼层

回帖奖励 +40 金钱

import random


total = 0


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

cal()
回复

使用道具 举报

4

主题

38

回帖

1659

积分

金牌会员

积分
1659
发表于 2022-1-22 15:08:54 | 显示全部楼层

回帖奖励 +40 金钱

import random
total= 0


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












cal()
print(total)
回复

使用道具 举报

5

主题

36

回帖

-182

积分

限制会员

积分
-182
发表于 2022-1-22 15:05:43 | 显示全部楼层

回帖奖励 +40 金钱

import random


total = 0


def cal():
    global total
    box = random.choice(['石头','黄金','钻石'])
    if box =='石头':
        total = total +20
    elif box =='黄金':
        total = total +5656
    else :
        total = total + 234
    print(total)
cal()
回复

使用道具 举报

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

本版积分规则

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