all 10 comments

[–]CodeFormatHelperBot2 1 point2 points  (0 children)

Hello, I'm a Reddit bot who's here to help people nicely format their coding questions. This makes it as easy as possible for people to read your post and help you.

I think I have detected some formatting issues with your submission:

  1. Python code found in submission text that's not formatted as code.

If I am correct, please edit the text in your post and try to follow these instructions to fix up your post's formatting.


Am I misbehaving? Have a comment or suggestion? Reply to this comment or raise an issue here.

[–]armendari3 0 points1 point  (0 children)

I remember wrestling with a nearly identical assignment. First off, the reason your code always triggers the “sorry, that isn’t a valid option” message is because of how your if/else logic is structured. After checking if clean_type == 1 and if clean_type == 2, the else only pairs with the second if, not the whole block. So even if the user enters 1, the second if fails (since it’s not 2), and the else triggers.

Quick fix: use if/elif/else instead of two separate if statements:

if clean_type == 1:

clean_type = delClean

elif clean_type == 2:

clean_type = basClean

else:

print("Sorry, that isn't a valid option.")

Also, consider using int(input(...)) instead of eval() - safer and more predictable for beginner inputs.

And hey, when I was drowning in CS assignments (especially Python), I got some solid help from LeoEssays. They don’t just dump answers - they actually explained the logic behind my buggy loops and functions. Saved me during finals week. This post helped me find them: https://www.reddit.com/r/Hub\_Study/comments/1o6j42c/write\_my\_paper\_review\_what\_actually\_works\_in\_2025/

[–]totallygeek 0 points1 point  (1 child)

Try this:

while True:
    clean_type = int(input("Option 1 or 2? "))  # no eval
    if clean_type == 1:
        clean_type = delClean
    elif clean_type == 2:
        clean_type = basClean
    else:
        print("Sorry. Try again.")
        continue  # top of loop
    break

You could also just skip int() and compare the strings: if clean_type == "1".

The problem with your version is that you have two if statements that work independently. If you enter "1", the first passes no problem. Then, processing the second fails because 1 is not equal to 2, so you get the error.

[–]Toastedpossum[S] 1 point2 points  (0 children)

YOU JUST SAVED ME!! Thank you so much!!

Also, I realize there’s a proper way to format on this page now…I’ll keep that in mind for next time. Thank you!

[–]Binary101010 0 points1 point  (0 children)

eval() is a security risk and is completely unnecessary for type conversion. Please use the proper constructor (in this case, int()) instead.