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

The variables Trick and Treat shouldn’t really be there at all.

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


Now any letter I enter will become “treat true” Not treat = 5 canies

I feel like an easier approach would be to get the userinput and then check if the input is A or B

This came back. That is bad.

It shouldn’t be here either.

Or here

or here

or here


Those parts of the code are not actually helping you. All Trick and Treat are doing is making things more complicated.

2 Likes

Duplicate accounts get flagged by the system as spam. Please don’t make duplicate accounts. The system should let you make additional posts with this account now.

You don’t need to scrap everything, just the parts with Trick or Treat.

You are correctly reading in a value from the user.

Now you should check if that value is 'A' by using the comparison operator ==.

Man i just dont know could you show me an example of that

Idk how to use a == operator

Right now your variable name is x (which you should still change to be a better name)
But you want to check if x equals “A”

1 Like

Well, part of learning how to program is learning how to look up stuff.

So let’s see what we get when we Google “Python == operator”
The first result is the official documentation

That isn’t super easy to read though. What about another link

This one seems more promising.

== Returns True if both the operands are equal 12 == 3 returns False

So how does it look like the == operator works when comparing two values?

like a == x it says a isnt defined how do i define it

This code says a equals x

But there is no variable in a in your code.
So you want to say x equals “A”

1 Like

Without quotes, a is just a variable.

With quotes "a" is the letter “a”.

You want to check if the variable x holds the letter "a".

This is part of why I don’t like single letter variable names. It is harder to read than it should be.

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

like that?

You still need to remove this.

And this

And this

And this

And this

And now this too.


Here you take in a letter from the user.
You want to check if the letter stored in x is "a" and then if it is print "Treat".

That all should be exactly 3 lines of code.

Line 1: Take input from the user

Line 2: Check if the input is "a"

Line 3: Print "Treat" if it is


x = input("Enter a Letter: ")
if Treat:
 if Trick:
"A" == x

This still shouldn’t be there.


I feel like you would benefit greatly from a basic programming tutorial.

how do i make it print treat if it is

x = input("Enter a Letter: ")
 "A" == x

just how though? can you tell me

We don’t write code for users here.

You really need to do some basic lessons. If you don’t, you will just learn a bunch of incomplete syntax and terrible habits.

1 Like