-2

I'm doing this assignment:

A new fighting game has become popular. There are N number of villains with each having some strength. There are N players in the game with each having some energy. The energy is used to kill the villains. The villain can be killed only if the energy of the player is greater than the strength of the villain.

Input:

1
6
112 243 512 343 90 478
500 789 234 400 452 150

Output:

WIN

This is my code:

def main():
    T = int(input(''))
    for i in range(T):
        N = int(input(''))
        strength = []
        energy = []
        for i in range(N):
            strength.append(int(input()))
        for i in range(N):
            energy.append(int(input()))
        strength.sort()
        energy.sort()
        for j in range(len(energy)):
            if strength[i] < energy[i]:
                continue
            else:
                return print('LOSE')
        return print('WIN')

main()

But I'm getting this error:

Traceback (most recent call last):
  File "CandidateCode.py", line 23, in 
    main()
  File "CandidateCode.py", line 11, in main
    strength.append(int(input('')))
ValueError: invalid literal for int() with base 10: '112 243 512 343 90 478 '

How can I solve this problem?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • 3
    You should post the code here instead of pictures of it. – dome May 18 '19 at 09:14
  • 1
    Anyway the error is self explanator. You are trying to convert the string `112 243 512 343 90 478` to an `int`. – dome May 18 '19 at 09:17
  • we can't perform that ? then how to take integer input – ramabrahmam botla May 18 '19 at 09:23
  • 1
    In an interactive Python console try running `int('3')`. What does this do? Next try running `int('1 2 3')`. What happens? Check the [documentation for int](https://docs.python.org/3/library/functions.html#int). – Iguananaut May 18 '19 at 10:45
  • Possible duplicate of [Get a list of numbers as input from the user](https://stackoverflow.com/questions/4663306/get-a-list-of-numbers-as-input-from-the-user) – Gino Mempin May 18 '19 at 10:48

1 Answers1

0

You can input each number one by one and cast each to int. If you want to input all numbers at once you can do this:

in = input()
numbers = list(map(int, in.split(' ')))

The map function apply int() to each element of the list which is obtained by splitting the input with the whitespace character. Then you have to convert the result to a list as in python-3 the map function returns an iterator.

dome
  • 820
  • 7
  • 20