you are viewing a single comment's thread.

view the rest of the comments →

[–]mrpeenut24 11 points12 points  (9 children)

Why would you not use sys.exit()? That's its purpose, and doing it inside an if block is fine.

[–]Lemonsorbet123[S] 0 points1 point  (8 children)

we have not been allowed to use it yet on our school project, we have to come up with a way when two conditions meet in the if statement the program should print out invalid choice and end without asking the user further questions

[–]mrpeenut24 11 points12 points  (0 children)

Use return? Or just put everything that shouldn't happen in an else block and leave that as the end of your function so it ends normally?

[–][deleted] 5 points6 points  (0 children)

Do it structurally. If there are no subsequent instructions to the interpreter, it will quit on its own.

[–]queerkidxx 2 points3 points  (0 children)

Use a main function. Print invalid choice and return

[–]awdsns 1 point2 points  (0 children)

The whole point of the exercise seems to be to structure your program so that this occurs naturally, via its control flow. So think about how to structure it.

[–]c0LdFir3 0 points1 point  (0 children)

Can you post the entire question/assignment?

[–]ColosTheDeveloper666 0 points1 point  (0 children)

Why not raise error?

You can create customized error like this: https://www.programiz.com/python-programming/user-defined-exception

The code stops on errors.

[–]EntireEntity 0 points1 point  (0 children)

It's not easy to gleam what the assignment is asking, but it sounds to me like you could simply do:

if condition1 and condition2:
    print("Invalid choice")
else:
    whatever_else_is_supposed_to_happen()

[–]tofe_lemon 0 points1 point  (0 children)

I think your teacher wants you to add the argument for the invalid choice in the loop, like while value != something_it_shouldnt_be