-2

I'm making a simple lottery game.

For instance, this is a sample randomized output from my lottery:

winning_num =  [1, 2, 4, 3]

Then this is the sample output from prompting the user to input 4 values:

guessed_num =  ['1', '2', '4', '3']

whenever i compare them it returns me False, obviously because they're different from each other. So I want to know how to remove the (') character in the guessed_num so it would be same and possibly give me a True.

I can't simply remove the (') char, I need a function to remove them.

equinox_xy
  • 25
  • 6
  • 1
    @sushanth I think the problem is more than that, he doesn't understand the concept of types – azro Aug 22 '21 at 13:17

2 Answers2

0

The input() function returns a string of the user's input, meaning when you put the user's guesses into guessed_num you are making a list of string variables, so obviously they will not be equal to integer numbers. So you need to make it a number, like so:

   guessed_num = [int(i) for i in guessed_num]

Input: guessed_num = ['1', '2', '4', '3']

Output: guessed_num = [1, 2, 4, 3]

aydee45
  • 516
  • 3
  • 14
0

You seems to not understand the nature of your content. The simple quote ' is not part of your content, that simply indicate that your content is a string, whereas 5 without quotes (as display) is an int, a number

So what you need is a conversion

x = '5' # type str
x = 5   # type int
5 == int('5')

So

guessed_num = [int(i) for i in guessed_num]
azro
  • 53,056
  • 7
  • 34
  • 70
  • Or ```list(map(int, guessed_num))``` but I don't think it will make any difference :) –  Aug 22 '21 at 13:19
  • no, it also comes with strings. so the guessed _num could be a list combination of int and str – equinox_xy Aug 22 '21 at 13:20
  • @equinox_xy, So instead of converting guessed_num to integers, you can convert `winning_num` to a list as `winning_num = list(map(str, winning_num))` – Rinshan Kolayil Aug 22 '21 at 13:30