r/learnpython • • Aug 11 '25

i dont know wat im doin, pls help

wsg everyone, im a newish pythoneer ( a term i created for python users),

I have this project im workin on and im a bit stuck any help and tip will be greatly appriciated

(it says somthing about invalid syntax with the numbers)

ty

# Get width input (5-10)
width = -1  # Start with invalid value
if width < 5 or width > 10:  # First check
    width = int(input("Enter width of swing (5-10): "))
    if width < 5 or width > 10:
        print("Out of range, please re-enter...")
        width = int(input("Enter width again (5-10): "))  # Second chance
        if width < 5 or width > 10:
            print("Using default width 5")
            width = 5

# Get steps input (10-50)
steps = 0  # Start with invalid value
if steps < 10 or steps > 50:
    steps = int(input("Enter number of timesteps (10-50): "))
    if steps < 10 or steps > 50:
        print("Out of range, please re-enter...")
        steps = int(input("Enter steps again (10-50): "))
        if steps < 10 or steps > 50:
            print("Using default steps 20")
            steps = 20
0 Upvotes

28 comments sorted by

4

u/acw1668 Aug 11 '25

It is better to post the full error traceback because it contains more information on the error.

-3

u/igneous-kek Aug 11 '25

i dont know what that means

4

u/acw1668 Aug 11 '25

As you said:

it says somthing about invalid syntax with the numbers

So post the full error messages.

Note that the posted code works for me and does not produce any error.

1

u/Ok-Promise-8118 Aug 11 '25

What is the full error you get -- don't summarize it, copy and paste it exactly here. It should also include a line number so we could see precisely where the problem is instead of having to guess.

1

u/csingleton1993 Aug 11 '25

So you know when you run the file and you see a bunch of stuff in the terminal that says stuff like "Error at line 43: Syntax Error" or whatever, and there can be multiple lines of that? All of that is called the "error traceback" - you want to copy the full message from the start to end, otherwise there is no way we can help you

2

u/smichaele Aug 11 '25

In order to get some real help you have to be more specific with your explanations and questions. Stating “I don’t know what I’m doing,” and describing an error as “it says something like…” is not helpful. What are you trying to do? What errors are you getting? What have you done to try to solve them? No one is going to write code for you for your project. That’s not what this subreddit is for, and you won’t learn anything.

0

u/igneous-kek Aug 11 '25

sorry, its my first time usin a sub like this, im usually jus on meme ones

im tryna write some code in a vim file in terminal, the errors are "TypeError : '<' not supported between instances of 'str' and 'int' "

i tried re-formatting the spaces (i think they r called idents?)

and im not tryna get anyone to do code for me, i just dont know where to start, its my first proper programming/python project and im also new to the software stuff, i did google a bunch and read thru the python tips sub but i still dont get it

2

u/LatteLepjandiLoser Aug 11 '25

This error means at some point you tried to make a comparison such as 1 < 'apple'. You can't check if an integer is greater or less than a string. That's what the error is telling you. It probably also contains the line number where that error occurred (but not pasted in here). Find the line and see what variables are being compared.

Possibly either of them is a user-input that didn't get cast to int, for instance comparing int(5) to str('5') just as an example.

2

u/Binary101010 Aug 11 '25

(it says somthing about invalid syntax with the numbers)

Please post the actual error, not your description of the error.

1

u/bahcodad Aug 11 '25

Your problem is that input returns a string. Even if you enter a number, Python will still treat it as a string. You need to convert it to an integer (or float if applicable)

0

u/SnipTheDog Aug 11 '25
width = -1  # Start with invalid value
if width < 5 or width > 10:  # First check
Do these lines really do anything?

-3

u/igneous-kek Aug 11 '25

i was told i needed a line to "initiate the code" so by using an invalid value you start with a check to set up the rest

4

u/csingleton1993 Aug 11 '25

Who told you that? You could also use a while loop

-3

u/igneous-kek Aug 11 '25

one of the dudes walkin around in my class, idk, he seemed to know what he was doing

(this is for a class project)

3

u/csingleton1993 Aug 11 '25

Yea uhhhh good rule of thumb is to not just take people at their word "because they seem to know what they are doing"

This person isn't completely wrong in that it is A way to do what you want, but to say it is NEEDED is a stretch (and where I'd consider it inaccurate)

1

u/Moikle Aug 11 '25

They are also still a beginner

1

u/ShadowRL7666 Aug 12 '25

In this case absolutely. Though I will say not everyone is a beginner in a class setting.

1

u/Moikle Aug 12 '25

Yes but it is far more common to find beginners who know just a little bit more than their peers, get overconfident and start telling them the wrong things. (Source: i was one)

1

u/ShadowRL7666 Aug 12 '25

Oh absolutely one of the biggest problems people face is thinking they know more than they do. I’ve been programming for several years I mainly do CPP. Though I will straight up say I don’t know if someone ask me something and I don’t know it. I’m not going to try and BS an answer.

5

u/Ok-Promise-8118 Aug 11 '25

If you used a while loop, that would actually have made sense. But here, you set the variable width to -1 and then instantly check if width is less than 5. You will get True and then go to the next line 100% of the time. You could eliminate those 2 lines (and similarly with the step variable) without any change in functionality.

2

u/Moikle Aug 11 '25

Whoever told you that doesn't understand python, or you didn't understand then

0

u/Due_Letter3192 Aug 11 '25

Hi there,

It's okay if you are stuck, this is how you learn.

It seems from what you mentioned that it is trying to compare a string with an integer. To narrow it further, could you copy-paste the whole error message that you get so we can narrow it down to the line itself?

-2

u/Invader_Mars Aug 11 '25

And this is why we don’t rely on AI

3

u/otteydw Aug 11 '25

OP didn't mention anything about AI.

-3

u/Invader_Mars Aug 11 '25

They don’t have to. It’s a class project, they can’t be bothered to understand the code, and the biggest indicator? The code itself. How did they write this, and get this far, without even understanding data types? Trace backs? And the comments obviously put in by AI.

3

u/otteydw Aug 11 '25

You think just because a new python dev wrote inefficient and repetitive code it must mean they used AI? You can't always attribute "I don't understand something" to AI usage. That is a large leap.

1

u/Invader_Mars Aug 11 '25

Look at their comments on this post, it’s a kid in a programming class not some “new Python dev”

1

u/otteydw Aug 11 '25

If the OP is trying to write code, that makes them a developer. Yes, the OP is an inexperienced (ie: new) developer. It still doesn't mean they used AI to generate what they have so far.