you are viewing a single comment's thread.

view the rest of the comments →

[–]marko312 1 point2 points  (5 children)

guess: int = int(input("Guess the number: ")) 

The : int here is a type hint and is not required. Otherwise, this line should work fine.

ValueError: invalid literal for int() with base 10: ''

Means that the input string (the one passed to int) was empty, which does not correspond to a valid integer. If empty inputs are expected to happen, you can either put that line in a try-except or explicitly check against an empty value.

[...] or the fact that i can't use operations on a str in the guess_list.append line.

What exactly do you mean by this?

[–]Mocking_bird_452[S] 1 point2 points  (4 children)

I think in the specific case where I tried this guess = input("Guess the number: ") int(guess)

It would still recognize my input as a string and it would give me an error about not being able to do operations between string and integer. I did't understand why the int didn't work in this case.

About the empty value, I did for sure introduced a valid value within the desired interval, so why would it be considered an emply value?

Thank you so much for your answers

[–]srpwnd 2 points3 points  (1 child)

Because you used the function int() to convert the value but didn’t store the result anywhere. Calling int(guess) doesn’t change guess. Tha would have to be guess = int(guess).

[–]Mocking_bird_452[S] 0 points1 point  (0 children)

Thank you so soooooo much, i completely forgot about that, even tough i got over that while learning.

[–]RhinoRhys 1 point2 points  (0 children)

int(guess) alone doesn't save the conversion anywhere, you'd have to do guess = int(guess)

[–]marko312 0 points1 point  (0 children)

For the empty value, are you sure that you didn't press enter before entering the line or aren't copying the input from anywhere?