|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
最近这样的程序都不能运行,vscode也不报错,就是不能运行
代码部分:
import random
tool = 1
game_3 = 0 #经验
game_2 = random.random(1,10)
while tool == 1:
print("1 练\n"
"2 走")
temp = input(">>>")
user_input = int(temp)
if user_input == 1:
game_3 = game_3 + game_2
game_2 = random.random(1,10)
print("增加了"+game_3+"的经验")
if user_input == 2:
break

本帖最后由 豆嘉木 于 2022-5-15 19:04 编辑
函数方法输入错了,第四行,不是random.random,应该是random.randint
还有一个问题,print("增加了"+game_3+"的经验")这里,game_3是一个整型,没法跟字符串拼接,要加上str
我给你修改了下:
- import random
- tool = 1
- game_3 = 0 #经验
- game_2 = random.randint(1,10)
- while tool == 1:
- print("1 练\n"
- "2 走")
- temp = input(">>>")
- user_input = int(temp)
- if user_input == 1:
- game_3 = game_3 + game_2
- game_2 = random.randint(1,10)
- print("增加了"+str(game_3)+"的经验")
- if user_input == 2:
- break
复制代码
|
|