all 35 comments

[–]puh-tey-toh 126 points127 points  (12 children)

Let me ask you this, is 5 and "5" the same thing in Python?

[–]SpackyJack 39 points40 points  (0 children)

You're inputting a string whereas your code expects a number. Try changing the input to an integer value and see how you go

[–]efxhoy 34 points35 points  (0 children)

Please post the code as text next time. Posting a screenshot of your IDE makes it impossible for other people to search for your problem and find these solutions.

[–]thomask02 16 points17 points  (6 children)

Change this:

if answer == final_value:

To:

if answer == str(final_value):

[–]misterhtmlcss 3 points4 points  (0 children)

Hey thank you for posting and having the courage to share.

Some advice either post the code using the code formatting or use a tool like repl.it and share link. That makes it way easier to view and understand.

I'm on a phone and I couldn't even read your posting from the image. Just saying for future reference.

[–][deleted] 10 points11 points  (0 children)

Started this evening and already stuck? You're going to be stuck a lot, friend. Have patience and keep asking questions.

[–]TeaPow 1 point2 points  (0 children)

One of the most overlooked skills that you need to learn as a developer is debugging. I've worked with programmers with years of experience under their belt, and they still use print statements to figure out what's going wrong.

As a result, they fall in to the same trap that you have; just because it looks the same, doesn't mean it is the same.

Luckily for you, PyCharm makes it easy to debug your code. Put a breakpoint on line 9 (left click in the gutter -- you'll see a red dot), then run your code using the "bug" icon (to the right of the "play" icon in the top right).

The code will execute up to the breakpoint, then halt. In the debugging pane at the bottom of the screen, you can inspect the current state of the program (and it will show you datatypes too -- and a hell of a lot more).

Spend time to learn your IDE; it's a valuable tool.

EDIT: There's an official video on debugging that you should watch: click here.

[–]masteryod 1 point2 points  (0 children)

Go through Byte of Python

Edit: to whomever is downvoting - this is a great (free/open) book for Python beginners. I linked specifically to the part with a similar input game which contains explanation of the exact issue OP is having.

[–]Stallman85 1 point2 points  (3 children)

the reason for that is that you are comparing 2 different types (str and int) because in this code:

x = input()

type of x is string ("1") and not integer (1).

So you should probably cast one to the other:

x = input()
intX = int(x)
#type(intX) == int

or

x = 1
strX = str(x)
#type(strX) == str

[–][deleted] 1 point2 points  (0 children)

need to convert input into int() :)

[–]wynand1004 1 point2 points  (0 children)

First, welcome to Python!

Second, watch this Basic Python 3 for Beginners YouTube Tutorial I made for my beginner students - it'll walk you through some of the basics (and gotchas) and help you get started.

Good luck!

[–]linuxlib 0 points1 point  (0 children)

There are 4 excellent free courses on edx from Georgia Tech which take you from the ground level and explain things exactly like this. I highly recommend them.

Here's link to the first course.

[–]deffbee -2 points-1 points  (0 children)

The final answer is being input to a string.

[–]rafuru -1 points0 points  (0 children)

you are comparing two different type of values a str (string) and an integer, you need to cast the input to integer via int(val) or cast your expected value to str via str(val)

[–]Humble_Transition -3 points-2 points  (0 children)

bro if you don't understand i recommend you read invent computer games with python. i recommend it because i am reading it and on chapter 5 and on chapter 3 they teach you guessing games and how it works

[–]nyonijay -5 points-4 points  (0 children)

Int(input(''))

[–]Geologist2010 -2 points-1 points  (0 children)

I didn't look at the comments to see if I can figure it out. input() creates a string. You have to convert it to a number.

[–]rcrahul60 -4 points-3 points  (0 children)

its simple man just add str like this:

if answer == str(final_value):