Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Console.ReadLine Method in python

Tags:

python

I am a total beginner to python and coding. I Was just wondering if there is a way for python to read what I've typed into the console, For example: If it prints out a question, I can answer with many choices. This is what I've tried yet.

`answer = input("Vilken?")
if answer.lower().strip() == "1":
    print("Okej! (1)")
elif answer.lower().strip() == "2":
    print("Okej! (2)")
elif answer.lower().strip() == "3":
    print("Okej! (3)")`

I got the code from a guy on youtube, for some reason, it doesn't read what I'm typing in. I am trying to store what the player types on a variable, so I can later use it. In c# I used string (variable name) = Console.Readline() If there is a way to do this is python, please let me know.

like image 594
AaronKanaron Avatar asked Sep 06 '25 13:09

AaronKanaron


1 Answers

this will solve your issue:

answer = raw_input("Vilken?")
if answer.lower().strip() == "1":
    print("Okej! (1)")
elif answer.lower().strip() == "2":
    print("Okej! (2)")
elif answer.lower().strip() == "3":
    print("Okej! (3)")

change input to raw_input

like image 56
Night King Avatar answered Sep 09 '25 17:09

Night King