如何在python 3.3.2中找到两个变量之间的区别

时间:2014-03-31 17:15:43

标签: python python-3.3 divide difference

我一直在为一个项目的小游戏创建代码并遇到一个我无法解决的小错误,所以我想知道是否有人可以帮助我。代码需要找到用户输入的两个变量之间的差异,这是目前为止的代码;

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 :(得分: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