I am trying to create a new list performing element-wise substruction of two python lists as follows:
from operator import add
number_villains_players = 0
villain_strength = []
player_strength = []
resulten_strength = []
def get_villain_strength(size):
villain_strength = [int(x) for x in input("Enter {} numbers of space separated strength of Villains:".format(size)).split()]
print(villain_strength)
def get_player_strength(size):
player_strength = [int(x) for x in input("Enter {} numbers of space separated energy of Players:".format(size)).split()]
print(player_strength)
def compare_strength():
#resulten_strength = [m-n for (m,n) in zip(player_strength,villain_strength)] #doesn't work
#resulten_strength = [sum(x) for x in zip(player_strength, villain_strength)] #doesn't work
#resulten_strength = [list( map(add, player_strength, villain_strength) )] #doesn't work
resulten_strength = [a*b for a,b in zip(player_strength,villain_strength)] #doesn't work
print(resulten_strength)
def main():
number_villains_players = input("How many Players/Villains?:")
get_villain_strength(number_villains_players)
get_player_strength(number_villains_players)
compare_strength()
if (i > 0 for i in resulten_strength):
print("WIN")
else:
print("LOSE")
main()
But print(resulten_strength)
is always empty as []
or [[]]
I have followed all the possible solutions from:
- Element-wise addition of 2 lists?
- How to mathematically subtract two lists in python? [duplicate]
- How to perform element-wise multiplication of two lists in Python?
Can anyone point me where I am going wrong?