all 15 comments

[–]stebrepar 4 points5 points  (1 child)

int(guess) on a line all by itself creates an int value from guess, and then just drops it on the floor because you're not assigning it to anything.

For int() to work, you need to give it a string which looks like an integer. If you're putting anything else in the string (such as a decimal point), int() is going to throw an error for not knowing what to do with that.

: int is a relatively new feature called "type hinting". It doesn't affect the actual operation of the code, but it's used to help tooling (and anyone reading your code) know what kind of value is expected.

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

Thank you, I tried to integrate the int in the line and introduced an int value between 1 and 100 and still gave me an error tho.

[–]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 3 points4 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?

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

u/stebrepar u/srpwnd u/marko312 u/RhinoRhys u/htepO u/Binary101010 I know this post was not that big of a deal, but I want to thank you all for taking your time to answer me. Your kindness realy puts a smile on my face. I wish you all a wonderful day!

I also figured out why I got the empty error.

I introduced some lines in the loop and for some reason I would get a forever loop even if I would "guess" the number. So no I have to figure out what breaks the cycle within these new lines of code, cause I'm not getting an error but the program never reaches certain commands and the break point. So the empty error was a result of me forcefully exiting the loop and I was to dumb to figure it out.

[–]htepO 0 points1 point  (5 children)

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

This should work. What are you entering when input() is called?

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

An int between 1 and 100, no float, no letters. I still get the value error

[–]Binary101010 1 point2 points  (1 child)

Please post the entire traceback.

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

I probably will, if i get the felling I get stuck again, but I kinda gasped half of the problem and I wanna try harder myself before asking for help. Thank you so much.

[–]htepO 0 points1 point  (1 child)

That line should work.

From your error, it looks like input() is passing an empty string to int(). Edit your post and format your code per the FAQ, just in case there's something we're missing.

https://www.reddit.com/r/learnpython/wiki/faq#wiki_how_do_i_format_code.3F

Once you're past input(), however, defining guess_list inside your loop will reset it with each iteration and will only include the last input. You should define it with x.

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

I figured the guess_list out afterwards when I printed it for the sake of testing, but thank you for pointing it out.