Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def calculator(history):
- c = "ez"
- calc = "1.Saberi\n2.Oduzmi\n3.Pomnozi\n4.Podjeli\nType fakamada to exit"
- while(c!="fakamada"):
- print(calc)
- a = int(input("Daj mi prvi broj: "))
- b = int(input("Daj mi drugi broj: "))
- d = int(input("Daj mi operaciju: "))
- if d<1 or d>4: print("you are shit my friend")
- elif d==1: print(saberi(a, b, history))
- elif d==2: print(oduzmi(a,b, history))
- elif d==3: print(pomnozi(a,b, history))
- elif d==4: print(podjeli(a,b, history))
- c = input("Again?");
- def saberi(a, b, h):
- h.append(["Saberi", a, b, a+b, "Rezultat: "+str(a) +" + "+ str(b) +" = " + str(a+b)])
- return h[-1]
- def oduzmi(a,b,h):
- h.append(["Oduzmi", a, b, a-b, "Rezultat: "+str(a) +" - "+ str(b) +" = " + str(a-b)])
- return h[-1]
- def pomnozi(a,b,h):
- h.append(["Pomnozi", a, b, a*b, "Rezultat: "+str(a) +" * "+ str(b) +" = " + str(a*b)])
- return h[-1]
- def podjeli(a,b,h):
- if b==0:
- h.append(["Podjeli", a, b, "NaN", "Rezultat: "+str(a) +" / "+ str(b) +" = " + "YOU SHALL NOT PASS"])
- print("Ne mozes djelit sa 0")
- return h[-1]
- h.append(["Podjeli", a, b, a/b, "Rezultat: "+str(a) +" / "+ str(b) +" = " + str(a/b)])
- return h[-1]
- calchistory = []
- calculator(calchistory)
- for i in calchistory:
- print(i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement