Answers for "how to check for error in python"

25

try except python

try:
  print("I will try to print this line of code")
except ERROR_NAME:
  print("I will print this line of code if error ERROR_NAME is encountered")
Posted by: Guest on February-01-2020
0

how to find error in python code

class Dogs:
#Constructor method that creates an instance of a dog
 #@param dname, the name of the dog
 #@param dbreed, the breed of the dog
 #@param dsize, the size of the dog
 def __init__(self, dName = "One", dBreed = "Sheppard", dSize = "Large"):
     self.name = dName
     self.breed = dBreed;
     self.size = dSize;
 #method jump makes the dog jump specified number of times
 #@param number which specifies the number of times the dog would jump
 def jump(self, number =1):
     for i in range(1,number+1):
         print("Jumps " , i , " times.")
     print()
 #method roll makes the dog roll specified number of times
 #@param number which specifies the number of times the dog would roll
 def roll(self,number):
     for i in range(1,number+1):
         print("Rolls " , i , " times.")
     print()
 #method pushcart makes the dog push the cart
 #in a specified direction for specified number of times
 #@param direction which specifies the direction in which the cart would be pushed
 #@param number which specifies the number of times the dog would push the cart
 def pushCart(self, direction, number):
     for i in range(1,number+1):
         print("Pushes " ,direction , " " , i , " times.")
     print()
 
 #method jumpHoop makes the dog jump hoops
 #@param number which specifies the number of times the dog would jumps hoops
 def jumpHoop(self,number):
     for i in range(1,number+1):
         print("Jumps Hoop " , i , " times.")
     print()
 #method printInfo prints the information; the name, breed and size of the object
 def printInfo(self):
     print("Name:",self.name)
     print("Breed:",self.breed)
     print("Size:",self.size)
     print()
#define the main method that tests the class definition
def main():
 #Creates four instances of dogs:
 #Kia, Tinky, Otto and Misty
     dog1 = Dog("Kia","Aidi", "Medium")
     dog2 = Dog("Tinky","Eskimo", "Small")
     dog3 = Dog("Otto","Akita", "Small")
     dog4 = Dog("Misty","Beagle", "Small")
     dog1.printInfo()
     dog1.jump(5)
     dog2.printInfo()
     dog2.roll(2)
     dog3.printInfo()
     dog3.pushCart("forward", 4)
     dog4.printInfo()
     dog4.jumpHoop(2)
main()
Posted by: Guest on July-09-2021

Code answers related to "how to check for error in python"

Python Answers by Framework

Browse Popular Code Answers by Language