how to find error in python code

Solutions on MaxInterview for how to find error in python code by the best coders in the world

showing results for - "how to find error in python code"
Noe
19 Feb 2016
1class Dogs:
2#Constructor method that creates an instance of a dog
3 #@param dname, the name of the dog
4 #@param dbreed, the breed of the dog
5 #@param dsize, the size of the dog
6 def __init__(self, dName = "One", dBreed = "Sheppard", dSize = "Large"):
7     self.name = dName
8     self.breed = dBreed;
9     self.size = dSize;
10 #method jump makes the dog jump specified number of times
11 #@param number which specifies the number of times the dog would jump
12 def jump(self, number =1):
13     for i in range(1,number+1):
14         print("Jumps " , i , " times.")
15     print()
16 #method roll makes the dog roll specified number of times
17 #@param number which specifies the number of times the dog would roll
18 def roll(self,number):
19     for i in range(1,number+1):
20         print("Rolls " , i , " times.")
21     print()
22 #method pushcart makes the dog push the cart
23 #in a specified direction for specified number of times
24 #@param direction which specifies the direction in which the cart would be pushed
25 #@param number which specifies the number of times the dog would push the cart
26 def pushCart(self, direction, number):
27     for i in range(1,number+1):
28         print("Pushes " ,direction , " " , i , " times.")
29     print()
30 
31 #method jumpHoop makes the dog jump hoops
32 #@param number which specifies the number of times the dog would jumps hoops
33 def jumpHoop(self,number):
34     for i in range(1,number+1):
35         print("Jumps Hoop " , i , " times.")
36     print()
37 #method printInfo prints the information; the name, breed and size of the object
38 def printInfo(self):
39     print("Name:",self.name)
40     print("Breed:",self.breed)
41     print("Size:",self.size)
42     print()
43#define the main method that tests the class definition
44def main():
45 #Creates four instances of dogs:
46 #Kia, Tinky, Otto and Misty
47     dog1 = Dog("Kia","Aidi", "Medium")
48     dog2 = Dog("Tinky","Eskimo", "Small")
49     dog3 = Dog("Otto","Akita", "Small")
50     dog4 = Dog("Misty","Beagle", "Small")
51     dog1.printInfo()
52     dog1.jump(5)
53     dog2.printInfo()
54     dog2.roll(2)
55     dog3.printInfo()
56     dog3.pushCart("forward", 4)
57     dog4.printInfo()
58     dog4.jumpHoop(2)
59main()
60
61
Lennart
14 Mar 2020
1print ("Welcome to the vending machine, type a product code: 1001 or 1002 ")
2product_code = int(input())
3KitKat_price = 2
4doritos_price = 2.5
5if (product_code == 1001):
6  print("You have selected" , + (product_code))
7  print("The price of the Kit Kat is 2$. Insert the neccesary coins")
8  customer_money
9  customer_money = int(input())
10  if customer_money == KitKat_price:
11    print("You have inserted 2$, KitKat is dispensing "
12  if customer_money > KitKat_price:
13    print("You have insterted more than 2$")
14  if customer_money < KitKat_price:
15    print("You have not inserted enough coins, instert more coins to get the KitKat")
16if (product_code == 1002): 
17  print("You have selected", + (product_code))
18  print("The price of the doritos is 2.5$. Insert the neccesary coins:")
19  customer_money = float(input())
20  if customer_money > doritos_price:
21    print("You have inserted more than 2.5$")
22  if customer_money < doritos_price:
23    print("You have not insterted enough coins, insert more coins to get the doritos")
24  if customer_money == doritos_price:
25    print("You have inserted 2$")
26    print("Doritos is dispensing")
27else:
28  print("You have not selected any product code")
29