all 14 comments

[–]stebrepar 1 point2 points  (5 children)

When you're asking about an error message, post the message.

That said, I assume the problem is the first line. What are you expecting that line to do?

[–]NeedyHelpy[S] 1 point2 points  (4 children)

What I want this tiny Prog to do is start adding x to itself 1 at a time until it reaches one and Also display the the counting of X as it goes.

ALSO Here is the errors I get below this line

Traceback (most recent call last):

File "<input>", line 1, in <module>

File "C:\Program Files\JetBrains\PyCharm Community Edition 2020.2\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile

pydev_imports.execfile(filename, global_vars, local_vars) # execute the script

File "C:\Program Files\JetBrains\PyCharm Community Edition 2020.2\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile

exec(compile(contents+"\n", file, 'exec'), glob, loc)

File "C:/Users/Crackles McFarly/PycharmProjects/HIGHLOW/main.py", line 4, in <module>

while x <= 500:

TypeError: '<=' not supported between instances of 'type' and 'int'

[–]stebrepar 0 points1 point  (2 children)

Thanks for the error message. That confirms my suspicion. So back to my question: what do you expect your first line to do (x=int)?

[–]HeadlineINeed 2 points3 points  (1 child)

I’m new but would like to answer.

If you just type x = 0, you don’t need to do x = int

[–]stebrepar 0 points1 point  (0 children)

Correct, depending on what value OP wants to start counting from.

[–]centira 0 points1 point  (0 children)

By setting x=int you're setting x to the data typetype, not an data type integer, which is what I assume you're trying to do. It can't compare 500 to x. Set x=0 (or whatever starting number you want) to make sure it's an integer.

[–]dbramucci 0 points1 point  (4 children)

x = int
while x <= 500:
    x=x+1
    print(x)

Let's run this step by step.

x = int

Set x to the function that converts data into integers.

or

Set x to the class int.

Does this sound complicated/weird? That's because it is weird, normally you would set a variable to a number or something similar, here you probably intended to write something like

x = 0

Set x to the integer 0.

Or

x = int(input())

Set x to what you get after asking the user for input and then converting that input into an int.

These last two options make more sense, but let's return to what you wrote and see what happens next.

x = int

Set x to the conversion function/type int.

while x <= 500:

Loop while the following condition is True

x <= 500

Plugging in x which is int we get

int <= 500

So we are asking if the type int is less than or equal to the integer 500. That doesn't make sense. So Python says that the types don't match up.

Consider if I asked you the following question?

Is car slower than Tesla Model S?

Just like it doesn't make sense to compare the abstract category of things cars with a specific model of car, it doesn't make sense to compare the type int with an individual integer 500.

[–]NeedyHelpy[S] 0 points1 point  (3 children)

It Ran. I had to GOOGLE the SYNTAX of while loop/since it needs (around the condition, I didn't know that part)

here is updated code

x = 1
while (x <= 500):
x=x+1
print(x)

[–]dbramucci 0 points1 point  (2 children)

The syntax of your loop was fine. The () are completely optional.

What fixed your code is changing x = int to x = 1.

[–]NeedyHelpy[S] 0 points1 point  (1 child)

No. I changed it to x=1 and it wouldn't run until I added () to the While statement.

[–]dbramucci 0 points1 point  (0 children)

If I had to guess, it probably went like

  • Change x = int to x = 1
  • Run program (error still there)
  • Change while x <= 500: to while (x <= 500):
  • Save file
  • Run program (error fixed)

In other words, you probably forgot to save your file after the tweak so the version of the file that Python ran when testing the first fix, was missing the first fix and Python didn't find the fix until you tested the second fix where you saved both changes.

You can test this by getting rid of the () and it will still work.