|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
error handling
I hope somebody could tell me how i can make a python script handling errors i want that if a error is arise that the script starts all over from then beginning and not that is is printing the error.
thank u for helping me! |
|
#2
|
||||
|
||||
|
This example uses try/except to handle bad inputs:
Code:
while 1:
ans = raw_input("Enter a number:")
try:
num = int(ans)
except ValueError:
print "Please enter only integers"
continue
try:
res = 1.0/num
except ZeroDivisionError :
print "Zero is not allowed!"
continue
break
print 1,"divided by ",num," = ",res
Grim ![]()
__________________
*** Experimental Python Markup CGI V2 *** |
|
#3
|
|||
|
|||
|
Thank you that was helping me a lot!
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > error handling |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|