Python Forum
Try except how is it working?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Try except how is it working?
#7
Practical, in the second version the program still runs even if a wrong input is givin. The exam is this afternoon and its brute force approach. I cannot use methods that are not in chap 1 to 4. So no append, no max and certainly no enumerate. Try, except was my weakness this is good info.
The bid idea is to use the Try specifically where you know it can return an error, the rest end up in else. Except only return the error message you want to put in.
This option remain the best for the exam:

print("Tapez trois valeurs numériques entières:")
try:
    val1 = int(input("Entrez première valeur:  "))
    val2 = int(input("Entrez deuxième valeur:  "))
    val3 = int(input("Entrez troisième valeur:  "))
except ValueError:
    print('Enter only whole numbers') 
else:
    if val1 > val2 > val3:
        print('Value 1 is greater ',val1)
    elif val2 > val3:
        print('Value 2 is greater,', val2)
    else:
        print('Value 3 is greater ',val3)
I put 'merde' out of frustration. Big Grin

Edit: i forgot to ask what about sys.exit() and import system? When do i need it?

Thank you sir!
Reply


Messages In This Thread
Try except how is it working? - by Frankduc - Feb-21-2022, 08:22 PM
RE: Try except how is it working? - by menator01 - Feb-21-2022, 08:48 PM
RE: Try except how is it working? - by Frankduc - Feb-21-2022, 09:00 PM
RE: Try except how is it working? - by deanhystad - Feb-21-2022, 10:20 PM
RE: Try except how is it working? - by Frankduc - Feb-21-2022, 10:25 PM
RE: Try except how is it working? - by deanhystad - Feb-22-2022, 04:47 AM
RE: Try except how is it working? - by Frankduc - Feb-22-2022, 02:54 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020