Advertisement
Guest User

riadexpert

a guest
Feb 24th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.46 KB | None | 0 0
  1. def calculator(history):
  2.    
  3.     c = "ez"
  4.     calc = "1.Saberi\n2.Oduzmi\n3.Pomnozi\n4.Podjeli\nType fakamada to exit"
  5.    
  6.     while(c!="fakamada"):
  7.         print(calc)
  8.         a = int(input("Daj mi prvi broj: "))
  9.         b = int(input("Daj mi drugi broj: "))
  10.         d = int(input("Daj mi operaciju: "))
  11.        
  12.         if d<1 or d>4: print("you are shit my friend")
  13.         elif d==1: print(saberi(a, b, history))
  14.         elif d==2: print(oduzmi(a,b, history))
  15.         elif d==3: print(pomnozi(a,b, history))
  16.         elif d==4: print(podjeli(a,b, history))
  17.        
  18.         c = input("Again?");
  19. def saberi(a, b, h):
  20.     h.append(["Saberi", a, b, a+b, "Rezultat: "+str(a) +" + "+ str(b) +" = " + str(a+b)])
  21.     return h[-1]
  22.    
  23. def oduzmi(a,b,h):
  24.     h.append(["Oduzmi", a, b, a-b, "Rezultat: "+str(a) +" - "+ str(b) +" = " + str(a-b)])
  25.     return h[-1]
  26.    
  27. def pomnozi(a,b,h):
  28.     h.append(["Pomnozi", a, b, a*b, "Rezultat: "+str(a) +" * "+ str(b) +" = " + str(a*b)])
  29.     return h[-1]
  30.    
  31. def podjeli(a,b,h):
  32.     if b==0:
  33.         h.append(["Podjeli", a, b, "NaN", "Rezultat: "+str(a) +" / "+ str(b) +" = " + "YOU SHALL NOT PASS"])
  34.         print("Ne mozes djelit sa 0")
  35.         return h[-1]
  36.     h.append(["Podjeli", a, b, a/b, "Rezultat: "+str(a) +" / "+ str(b) +" = " + str(a/b)])
  37.     return h[-1]
  38.    
  39.  
  40.            
  41. calchistory = []            
  42. calculator(calchistory)            
  43. for i in calchistory:
  44.     print(i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement