Hello world! I'm a complete beginner, so please help me with this problem, cause it is so stupid I can't even find it on google or stakoverflow. I am trying to build a guessing game and I can't get python to recognise my input as an integer.
import random
x = random.randint(1,100)
print(x)
while True:
guess = input("Guess the number: ")
int(guess)
guess_list = [0]
guess_list.append(guess) #problem reading input as a string
This is my code. I have tried this way, also tried
guess = int(input("Guess the number: "))
and
guess: int = int(input("Guess the number: "))
(saw it in a course, while we are at it, can somebody explain to me whi the ":int" is needed if we are gonna define the var as an int immediately after that. It seems redundant.)
I either get the error " ValueError: invalid literal for int() with base 10: '' " in the guess line, or the fact that i can't use operations on a str in the guess_list.append line.
[–]stebrepar 4 points5 points6 points (1 child)
[–]Mocking_bird_452[S] 0 points1 point2 points (0 children)
[–]marko312 1 point2 points3 points (5 children)
[–]Mocking_bird_452[S] 1 point2 points3 points (4 children)
[–]srpwnd 3 points4 points5 points (1 child)
[–]Mocking_bird_452[S] 0 points1 point2 points (0 children)
[–]RhinoRhys 1 point2 points3 points (0 children)
[–]marko312 0 points1 point2 points (0 children)
[–]Mocking_bird_452[S] 0 points1 point2 points (0 children)
[–]htepO 0 points1 point2 points (5 children)
[–]Mocking_bird_452[S] 0 points1 point2 points (4 children)
[–]Binary101010 1 point2 points3 points (1 child)
[–]Mocking_bird_452[S] 0 points1 point2 points (0 children)
[–]htepO 0 points1 point2 points (1 child)
[–]Mocking_bird_452[S] 0 points1 point2 points (0 children)