找回密码
 中文实名注册
查看: 1158|回复: 39

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

[复制链接]
回帖奖励 1280 金钱 回复本帖可获得 40 金钱奖励! 每人限 1 次

693

主题

1079

帖子

2万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
22836
发表于 2022-1-9 10:13:43 | 显示全部楼层 |阅读模式
【Python作业】第四单元 第4课  黄金矿工 全局变量
回复

使用道具 举报

7

主题

62

帖子

1128

积分

金牌会员

Rank: 6Rank: 6

积分
1128
发表于 2022-2-12 14:15:57 | 显示全部楼层

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

主题

41

帖子

838

积分

高级会员

Rank: 4

积分
838
发表于 2022-1-23 15:17:10 | 显示全部楼层

回帖奖励 +40 金钱

import random


total = 0


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


cal()
print(total)
回复

使用道具 举报

0

主题

13

帖子

456

积分

中级会员

Rank: 3Rank: 3

积分
456
发表于 2022-1-23 15:10:39 | 显示全部楼层

回帖奖励 +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

主题

32

帖子

891

积分

高级会员

Rank: 4

积分
891
发表于 2022-1-23 11:54:48 | 显示全部楼层

回帖奖励 +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)
回复

使用道具 举报

1

主题

33

帖子

1089

积分

金牌会员

Rank: 6Rank: 6

积分
1089
发表于 2022-1-23 11:54:43 | 显示全部楼层

回帖奖励 +40 金钱

import random


total = 0


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


cal()
print(total)
回复

使用道具 举报

15

主题

57

帖子

3170

积分

论坛元老

Rank: 8Rank: 8

积分
3170
发表于 2022-1-23 11:45:59 | 显示全部楼层
import random

total=0

def cal():
    global total
    box = random.choice(["a","s","d","TNT"])
    if box=="a":
        total = total+30
    elif box=="s":
        total = total+110
    elif box == "TNT":
        total = total-200

    else:
        total = total+500

cal()
print(total)
回复

使用道具 举报

5

主题

69

帖子

2243

积分

金牌会员

Rank: 6Rank: 6

积分
2243
发表于 2022-1-23 11:43:27 | 显示全部楼层

回帖奖励 +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)


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-200


cal()
print(total)
回复

使用道具 举报

13

主题

109

帖子

984

积分

高级会员

sgsdgsg

Rank: 4

积分
984
发表于 2022-1-23 11:41:36 | 显示全部楼层

回帖奖励 +40 金钱

[Python] 纯文本查看 复制代码
import random

total=0

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

    elif box='黄金':
        total = total+100
    else:
        total = total+500
回复

使用道具 举报

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

本版积分规则

小黑屋|东台市机器人学会 ( 苏ICP备2021035350号-1;苏ICP备2021035350号-2;苏ICP备2021035350号-3 )

GMT+8, 2024-3-28 21:12 , Processed in 0.046025 second(s), 30 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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