Ask coding questions

← Back to all posts
My python repl isn't working...
HarveyH (97)

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

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

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")

HarveyH (97)

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

WonderNote18 (4)

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.

ScottSennema (0)

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!


HarveyH (97)

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

ScottSennema (0)

@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.

Darklordx (5)

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")

TrevorBarron (23)

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:")))

Darklordx (5)

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

HarveyH (97)

@Darklordx It doesn't work still...

HarveyH (97)

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