Search code examples
pythonpython-3.3dividedifference

How to find the difference between two variables in python 3.3.2


I have been creating code for a small game for a project and have run into a small error which I can't fix, so I was wondering whether someone can help me. The code needs to find the differences between two variables input by the user, here is the code so far;

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)))]

Now I need to find the difference between the two variables and divide it by 5 to get a modifier, then store this value and take it off one player and add to another player, but I do not know how. I have looked online and I cant seem to find anything so is there anyone who can help me with this?


Solution

  • Convert your input to int and drop all those lists:

    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