How do I get a user input for my trick or treat code

Im trying to make a code so that if a user inputs a they get treat b they get trick but this is my code

x = input("Enter a number: ")
print(type(a))
trick = a

help please

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Hi @jdib0964 !

Welcome to the forum!

Can you explain a little bit more on what you are trying to do?
I am not really following along with the logic.

Also, I would highly suggest creating better variable names instead x and a.
Good variable names should describe what the variable actual is :grinning:

alrighty so im trying to make it so if the user types in the letter “A” It will print the word treat and if they type the letter “B” It will type Trick

Ok cool.

Well for starters, you are asking your user to give you a number.

But what you really want is for them to type in A or B.
You need to first change your message so the user knows what to input.
You should also consider that the user can type in lowercase a or b.
But that should still be a valid input.
So you will probably want the user input to always be a capital letter.
https://www.programiz.com/python-programming/methods/string/upper

You should also consider displaying a message if the user does not provide a valid input. Your code should ask for the prompt again.

Then you want to pick a better variable name then x.
So you can try user_input

The last part of the problem would be to write a condition that says if the user input is A then print treat otherwise print Trick.

Why don’t you give that a try.

If you have further questions, show your latest code attempt and we can go from there

i am pretty new to coding and this is very confusing to me

That’s fine. Everyone has to start somewhere. We are here to help. We are not here to do it for you though.

1 Like

That’s ok.
We are here to help :grinning:

Why don’t you try the first part where you have to ask for user input.

First work on changing the message so the user knows what to write

of course i know im just tryin to get a bit of help

Please copy-paste your code instead of taking pictures. Pictures are hard to work with.

1 Like

if i type a it says treat true how do i make it not say true also when i type b it says treat true and not trick

Treat = True
Trick = False
x = input("Enter a Letter: ")
print(type(x))
if Treat:
 print("Treat  "  +str(Treat))
 if Trick:
  print("Trick  "  +str(Trick))

These aren’t helping you. I would remove them.

You want to check if x is 'A' or 'B'. For that, you will need to use the comparison operator ==.

Also, you probably don’t want to print the type of x to the user.
So I don’t you need this line here

That doesn’t seem like useful information for the user to have

1 Like

when i do this it says treat isnt defined

If you made changes to your code it would help to see it :grinning:


x = input("Enter a Letter: ")
if Treat:
 print("Treat  "  +str(Treat))
 if Trick:
  print("Trick  "  +str(Trick))

i just need to define “A” to the word treat and “B” the the word trick so if the user inputs a or b it will be a treat or a trick!

It is undefined because you deleted this part.