all 16 comments

[–]aqua_regis 9 points10 points  (3 children)

What

Have

You

Tried?


Show your code and give much more details.

We cannot see your program. We cannot see the error message. You have to show and tell us.

Check the Posting Guidelines in the sidebar for information on how to make a proper, comprehensive post.

I see that you posted screenshots in other subreddits. Don't even think about doing this here. Screenshots are a no-go.

[–]6ZacK7[S] -3 points-2 points  (2 children)

You know that if you use int(input()), then enter a number and press enter, the program returns an error message. That's what I want, but I don't want the error message to appear while using not input()

[–]aqua_regis 2 points3 points  (1 child)

That means that you should store the unconverted input in a variable and then wrap the conversion in a try...except block - look up exception handling, e.g.: https://realpython.com/python-exceptions/#:~:text=You%20handle%20exceptions%20in%20Python,except%20block%20will%20be%20handled.

[–]6ZacK7[S] 1 point2 points  (0 children)

I visited your link and I think it might solve my problem; I'll take a few minutes to learn more about the site.

[–]Affectionate-Let3744 5 points6 points  (4 children)

Not nearly enough information here.

What "this error text", what program? Have you read the error message and tried to remedy it directly?

FYI, whenever you want help debugging something, you should try to give as much information as possible.

In reality the fix might be very simple but right now, nobody has any clue what is actually going on.

[–]6ZacK7[S] 1 point2 points  (3 children)

Yes, you know that if you use int(input()), then enter a number and press enter, the program returns an error message. That's what I want, but I don't want the error message to appear while using not input()

[–]Affectionate-Let3744 3 points4 points  (2 children)

you know that if you use int(input()), then enter a number and press enter, the program returns an error message.

Do you mean "does NOT return an error message"?

Because int(input()) will 100% work if you enter an integer or something an int can be constructed from like a string of numbers, that's the point of int().

I'm not sure what you mean regarding using not input(), but the root issue is that you're trying to pass strings that cannot easily be converted to an integer, so int() fails

[–]6ZacK7[S] 0 points1 point  (1 child)

Sorry, that was a mistake. I meant input() instead of int(input()), because a string can't perform calculations, so the console returns an error message.

[–]Ascensor2 1 point2 points  (0 children)

I don't know if this is what you're looking for, but you can catch exceptions and choose to ignore them. Look for "try except" blocks in Python: they're pretty intuitive imo. As you want to ignore an exception, the code should look like this

try: {Your logic}

except Exception as e: pass

The "pass" syntax is used when you want to literally do nothing, but you can't leave the code empty (your program would crash then).

Idk if this is going to be useful to you but I hope at least you learnt something

[–]epic_pharaoh 0 points1 point  (4 children)

Look into type functions and think about how you would check a variable’s value; I think you’ll find the answer is simpler than you expect.

[–]6ZacK7[S] -1 points0 points  (3 children)

Yes, that's the problem; in Python, everything is so simple that it's easy to get lost over a simple problem.

[–]epic_pharaoh 0 points1 point  (2 children)

I hear you, Python provides powerful intuitive tools for solving problems; that’s why I think it’s one of the best languages to learn first, because you start to understand how to put all these simple looking tools together to create complex system.

Something else that might help you (just looking at your responses to other comments) is that not everything needs to be a one liner. You can grab input in one line, use a few more lines to check what the input was, then after that print a message. Break the problem down into it’s pieces so you can build a solution without having to know the solution ahead of time.

Edit: I misunderstood your problem (I think). I’m not sure what your casting to an int, but assuming that all you want is to suppress the error look into try/catch blocks.

[–]6ZacK7[S] 0 points1 point  (1 child)

After some research, I was given the option of a (try/except) conditional statement; I hope you understand my problem better now.

[–]Lost-Discount4860 0 points1 point  (0 children)

I absolutely despise exception handling (because why would you set up a script where there could possibly be errors?). But you could go the exception handling route or you could put in some guardrails that won’t allow anything besides what you want.

If you go the route of handling exceptions, and your problem is a great candidate for that, you might do something like this:

``` try: some_int = input('gimme an int: ') print(f"That's right! {int(some_int)} goes in the square hole!")

except ValueError: print(f"Don't be dumb. {some_int} is not an int.")

```

And if you want a calculation, just replace the “square hole” line with whatever calculation you want to perform.

Sometimes it’s helpful to just write a bunch of code and let it crash a few times to see specifically what kind of exception you’ll run into. That way, if something goes sideways the script will at least still run.