0% found this document useful (0 votes)
6 views2 pages

Calculator Py

Uploaded by

amir.dlavr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Calculator Py

Uploaded by

amir.dlavr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import math

def add(x, y):


return x + y

def subtract(x, y):


return x - y

def multiply(x, y):


return x * y

def divide(x, y):


if y == 0:
return "‫ تقسیم بر صفر‬:‫"!خطا‬
return x / y

def power(x, y):


return x ** y

def square_root(x):
if x < 0:
return "‫ ریشه مربع عدد منفی‬:‫"!خطا‬
return math.sqrt(x)

def sin(x):
return math.sin(math.radians(x))

def cos(x):
return math.cos(math.radians(x))

def tan(x):
return math.tan(math.radians(x))

def calculator():
print(" ‫)"ماش ین‌حس اب پیش رفته‬
print("‫عملیات‬:")
print("1. ‫)"جمع‬
print("2. ‫)"تفریق‬
print("3. ‫)"ضرب‬
print("4. ‫)"تقسیم‬
print("5. ‫)"توان‬
print("6. ‫)"ریشه مربع‬
print("7. ‫)"سینوس‬
print("8. ‫)"کسینوس‬
print("9. ‫)"تانژانت‬

while True:
choice = input("‫) یا‬1/2/3/4/5/6/7/8/9( ‫لطفا عمل مورد نظر خود را انتخاب کنید‬
‫'خروج' برای پایان‬: ")

if choice == '‫'خروج‬:
print("‫)"!متشکرم! خداحافظ‬
break

if choice in ['1', '2', '3', '4', '5']:


num1 = float(input("‫عدد اول را وارد کنید‬: "))
num2 = float(input("‫عدد دوم را وارد کنید‬: "))

if choice == '1':
print(f"{num1} + {num2} = {add(num1, num2)}")
elif choice == '2':
print(f"{num1} - {num2} = {subtract(num1, num2)}")
elif choice == '3':
print(f"{num1} * {num2} = {multiply(num1, num2)}")
elif choice == '4':
print(f"{num1} / {num2} = {divide(num1, num2)}")
elif choice == '5':
print(f"{num1} ^ {num2} = {power(num1, num2)}")

elif choice == '6':


num = float(input("‫عدد را وارد کنید‬: "))
print(f"‫{ ریشه مربع‬num} = {square_root(num)}")

elif choice in ['7', '8', '9']:


angle = float(input("‫زاویه (درجه) را وارد کنید‬: "))

if choice == '7':
print(f"sin({angle}) = {sin(angle)}")
elif choice == '8':
print(f"cos({angle}) = {cos(angle)}")
elif choice == '9':
print(f"tan({angle}) = {tan(angle)}")

else:
print("‫ لطفا دوباره تالش کنید‬.‫انتخاب نامعتبر‬.")

if __name__ == "__main__":
calculator()

You might also like