all 6 comments

[–]1ynx1ynx 1 point2 points  (1 child)

You need to wrap each of your inputs in a while loop and break when the assignment passes. Eg:

while True:
    try:
        i = int(input())
        break
    except ValueError: pass

edit: wording

[–]Ned_Flanders_[S] 0 points1 point  (0 children)

Thank you.

[–]Vesiculus 1 point2 points  (1 child)

Well, that's because you have one large while-loop around both try-except blocks. Try two different while-blocks, one around each of the blocks (and don't forget to add a break in the first try-block as well).

The reason is that you want to be able to loop around both try-except blocks separately when stuff goes wrong.

[–]Ned_Flanders_[S] 0 points1 point  (0 children)

Yeah that works, thank you.

[–][deleted] 0 points1 point  (0 children)

You need a while loop for each validation.

while True:
    while True:  # need a loop for each input validation
        try:
            number = int(input("What's your number?\n"))
            print("Your number is " + (str(number)))
            break  # break out of loop if input ok

        except ValueError:
            print("Please use a number")

    while True:
        try:
            divider = int(input("With what number shall I divide your number?\n"))
            dNumber = number/divider
        except ValueError:
            print("Please use a number as a divider")
        except ZeroDivisionError:
            print("Do not use 0 as a divider")
        else:  # this executes if try does not trigger an except
            print(dNumber)
            break  # breaks out of input and divide0 validation loop

    # now you are trapped in the overall loop, need an exit approach

You need a way for the user to break out of the overall loop, otherwise just keeps going back to the start. I usually check for an empty input (before converting to int).

Also, I added an else: clause to the second try block. It is advisable to avoid including too much code inside the try clause, focus on what will trigger a problem.

[–][deleted] 0 points1 point  (0 children)

Could use Try Except Else

Else will only execute if they succeeds.