如何在Python 3.3.2中找到两个变量的差异
我正在为一个小项目制作游戏代码,但遇到了一个小错误,自己解决不了,所以想请教一下有没有人能帮我。这个代码需要找出用户输入的两个变量之间的差异,下面是目前的代码:
import random
print('Welcome to the game')
char1=[input('What is the fist characters name: ')]
char2=[input('What is the second characters name: ')]
char1st=[input('What is the strength of '+(str(char1)))]
char1sk=[input('What is the skill of '+(str(char1)))]
char2st=[input('What is the strength of '+(str(char2)))]
char2sk=[input('What is the skill of '+(str(char2)))]
现在我需要找出这两个变量之间的差值,然后把这个差值除以5,得到一个修正值。接着,我想把这个值存起来,从一个玩家那里减去,再加到另一个玩家身上,但我不知道该怎么做。我在网上查了很多资料,但似乎没有找到相关的信息,所以想问问有没有人能帮我解决这个问题?
1 个回答
0
把你的输入转换成 int
类型,然后把那些列表都去掉:
print('Welcome to the game')
char1=input('What is the fist characters name: ')
char2=input('What is the second characters name: ')
char1st=int(input('What is the strength of '+char1))
char1sk=int(input('What is the skill of '+char1))
char2st=int(input('What is the strength of '+char2))
char2sk=int(input('What is the skill of '+char2))
strmod = abs (char2st - char1st) / 5 # or // 5 for floor division
#and so on