mardi 22 novembre 2016

Python Issue: Try and Excepts with if

This is probably very basic but I am trying to trigger the Except to run if cointype() is not within the dictionary coin_int but it jumps straight out of the if without using the Except even if a value error is met? Thanks for any help

try:
    coin_type = input("Input your coin: 1p, 2p, 5p etc...  ")
    if coin_type in coin_int:
        print("That value is recognised inside the list of known coin types")

except ValueError:
    print("That value of coin is not accepted, restarting...")

Aucun commentaire:

Enregistrer un commentaire