Ask coding questions

← Back to all posts
My python repl isn't working...

My notepad i am coding isn't working, can you tell me why?

Answered by
LightninMcQuade (240)
[earned 5 cycles]
View Answer

How is it working now? I think your issue is the fact that it is looking for you to input an integer but you are entering a string therefore the error

To fix this:
remove the int() on your inp input

Also: if q is set to an integer earlier you need to specify this later

like this:
if inp == str("q")


@QuadeG1 It's working perfectly fine now, thnxs!


I guess it's been answered, but you're basically telling the user to type a number, and then asking the computer to see if that number equals the letter 'q'. Based on your w and e inputs, I'm guessing q is a variable, so remove the quotes.

Right now if I enter 2, you're checking:
"Does 2 equal q?"

Without the quotes, it becomes:
"Does 2 equal the value of q?"

Very different statements!



@ScottSennema I'm actually wanting the quotes because if I remove the quotes, I could put in 0 and have q as an output.


@HarveyH well then you need to remove the int from your input. Should just be inp = input('Type a letter?').

The error is because"q" can't be converted to a number. The int() function concerts a string to an integer, ie: "1" into 1. Make that Quick change and you won't see that error any more.


By the way, if you just want a program that prints the character you type in, you don't need such an extended if-elif statement. Just type
print(input("Type a letter."))
Alternatively, if you want to make sure it's only one letter, type
print(input("Type a letter.")[1:])
print("You didn't type anything")


when you use "input" in python the interface returns a string variable. applying int to a string doesn't make any sense. If you want a user input a number that you want to calculate with you would have to do something like this...
inp = eval(input("Enter a number: ")) ... or if you want it to be an integer... you could do this
inp=int(eval(input("Enter a number:")))


Since the variable q is set to 0 and youre asking the user to input a LETTER into an input formatted for INTEGERS, it's going to give a valueError stating that the letter 'q' cannot equal a number since it is a char.


It looks like you're checking if it's equal to the string "q" instead of the variable q. Remove the quotes.


@Darklordx It doesn't work still...


And by the way, i do have the variable q as 0.