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

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

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

4

主题

47

帖子

735

积分

高级会员

Rank: 4

积分
735
发表于 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)
回复

使用道具 举报

3

主题

45

帖子

1215

积分

金牌会员

Rank: 6Rank: 6

积分
1215
发表于 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)
回复

使用道具 举报

7

主题

62

帖子

1128

积分

金牌会员

Rank: 6Rank: 6

积分
1128
发表于 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

主题

29

帖子

86

积分

注册会员

Rank: 2

积分
86
发表于 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)
回复

使用道具 举报

2

主题

26

帖子

1558

积分

金牌会员

Rank: 6Rank: 6

积分
1558
发表于 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
回复

使用道具 举报

3

主题

73

帖子

1559

积分

版主

Rank: 7Rank: 7Rank: 7

积分
1559
发表于 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
回复

使用道具 举报

4

主题

83

帖子

3868

积分

论坛元老

Rank: 8Rank: 8

积分
3868
发表于 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)
回复

使用道具 举报

17

主题

82

帖子

4444

积分

版主

你爸爸

Rank: 7Rank: 7Rank: 7

积分
4444
发表于 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)

回复

使用道具 举报

4

主题

134

帖子

5209

积分

版主

Rank: 7Rank: 7Rank: 7

积分
5209
发表于 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)

回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-29 03:20 , Processed in 0.048151 second(s), 36 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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