cara bikin kalkulator sederhana python
Opened this issue · 1 comments
mahda1996 commented
def kalkulator(num1,operator,num2):
if operator == "+":
result = num1 + num2
print(result)
elif operator == "-":
result = num1 - num2
print(result)
elif operator == "*":
result = num1 * num2
print(result)
elif operator == "/":
if num2 != 0:
result = num1 / num2
print(result)
else:
print("Error: Tidak bisa dibagi dengan nol!")
return (result,6/2)
print("Hasil:",result)
kalkulator(1,'+',2)
kalkulator(3,'-',2)
kalkulator(4,'*',2)
kalkulator(6,'/',2)
3
1
8
3.0
orangeMangoDimz commented
bisa juga pakai try - except
python
elif operator == "/":
try:
result = num1 / num2
except ZeroDivisionError:
print("Error: Tidak bisa dibagi dengan nol!")