第003讲:小插曲之变量和字符串 | 课后测试题及答案
1.课堂小游戏:
print("人生苦短,我学python")
import random # 不能遗漏
a = int(random.randint(1, 10))
print("电脑猜的数字是", a)
Money = 500
print("初始金币:", Money, "帝国元")
temp = input("猜数字游戏开始,\n请输入你猜的数字(1~10),\n猜对获得500帝国元,\n猜错扣除100帝国元,\n一共3次机会:")
guess = int(temp)
count = 1
print("while的判断条件中,count=", count, )
while guess != a and guess >= 1 and guess <= 10 and count <= 2:
Money = Money -

本节介绍了变量命名规则,实战了Python中的字符串操作,包括print函数、随机数生成、字符串输入验证,以及小游戏中的while和if-else嵌套。还涉及了变量命名的错误示例和字符串转义。
最低0.47元/天 解锁文章
639

被折叠的 条评论
为什么被折叠?



