Calculator function
Write a function that receives two numbers with one operator (+ - / *) and does the relevant calculation and returns the result
Example:
cal(2, '+', 6) #8 cal(5, '-', 1) #4 cal(6, '/', 2) #3 cal(8, '*', 2) #16
Write a function that receives two numbers with one operator (+ - / *) and does the relevant calculation and returns the result
Example:
cal(2, '+', 6) #8 cal(5, '-', 1) #4 cal(6, '/', 2) #3 cal(8, '*', 2) #16
let msg = 'error' alert(msg)This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error' alert(msg)This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error' alert(msg)This answer is only visible to premium members
This answer is only visible to premium members
print("عملیاتهای موجود: +، -، *، /") print("برای خروج 'q' را وارد کنید.") while True: operation = input("عملیات (+, -, *, /) یا 'q' برای خروج: ") if operation == 'q': print("خروج از برنامه.") break if operation in ('+', '-', '*', '/'): num1 = float(input("عدد اول را وارد کنید: ")) num2 = float(input("عدد دوم را وارد کنید: ")) if operation == '+': print("نتیجه:", num1 + num2) elif operation == '-': print("نتیجه:", num1 - num2) elif operation == '*': print("نتیجه:", num1 * num2) elif operation == '/': if num2 == 0: print("خطا: تقسیم بر صفر ممکن نیست.") else: print("نتیجه:", num1 / num2) else: print("عملیات نامعتبر! لطفاً یکی از عملیاتهای +, -, *, / یا 'q' را وارد کنید.")
def calc(math): x=int(input("Enter x: ) y=int(input("Enter y: ) a="+","-","*","/" anw=eval(x,a,y) try: if x/0 or y/0: print("cannot divide by zero") expect: return calc print(calc())
number1 = int(input("enter numbr :")) number2 = int(input("enter numbr :")) operator = input("pleas enter the (+,-,*,/) :") def calculator(number1,number2,operator): """ این تابع دو مقدار را از کاربر میگیرد و عمل های ضرب,تقسیم,جمع,تفریق را انجام میدهد """ match operator : case "+" : result = number1 + number2 return (f"resalt : {result}") case "-" : result = number1 - number2 return (f"resalt : {result}") case "*": result = number1 * number2 return (f"result : {result}") case "/": result = number1 / number2 return (f"resalt : {result}") case _: return (f"access is not allowed") print(calculator(number1,number2,operator))
class Calculate: def __init__(self, num1, num2): try: self.__num1 = int(num1) self.__num2 = int(num2) except ValueError: raise ValueError("Invalid Input!") # just getter (can not to edit) @property def num1(self): return self.__num1 @property def num2(self): return self.__num2 def multiple(self): print(f"{self.__num1} * {self.__num2} = {self.__num1 * self.__num2}") def devision(self): if self.__num2 == 0: return "Zero devision" print(f"{self.__num1} / {self.__num2} = {(self.__num1 / self.__num2):.2f}") def sum(self): print(f"{self.__num1} + {self.__num2} = {self.__num1 + self.__num2}") def subtract(self): print(f"{self.__num1} - {self.__num2} = {self.__num1 - self.__num2}") def main(): obj = Calculate(input("Enter Number 1: "), input("Enter Number 2: ")) obj.multiple() obj.devision() obj.sum() obj.subtract() if __name__ == "__main__": main()
number_1 = float(input("please enter a number: ")) number_2 = float(input("please enter a number: ")) amalgar = input("please select oprator: + , - , / , * ") if amalgar == "+": print(f"{number_1} + {number_2} = ", number_1 + number_2) elif amalgar == "-": print(f"{number_1} - {number_2} = ", number_1 - number_2) elif amalgar == "/": print(f"{number_1} / {number_2} = ", number_1 / number_2) elif amalgar == "*": print(f"{number_1} * {number_2} = ", number_1 * number_2)
print("enter x:") x = input(int()) print("enter y:") y = input(int()) print("Enter - or + or * or /:") z = input() if z == '+' : print(x + y) elif z == '-' : print(x - y) elif z == '*' : print(x * y) elif z == '/' : print(x / y) else: print("Invalid operator. Please enter +, -, *, or /.")
def Mashin_Hesab(n) :
m = n.split()
x = 0
if m[1] == "+" :
x = int(m[0]) + int(m[2])
elif m[1] == "-" :
x = int(m[0]) - int(m[2])
elif m[1] == "*" :
x = int(m[0]) * int(m[2])
elif m[1] == "/" :
x = int(m[0]) / int(m[2])
return x
Submitting answers is currently unavailable.
Write a function that receives a string and returns the number of letters: To solve this question, you should not use ready-made functions for example: get_len ('code-bezan.ir') # 13
We want to open a cow door, we don't know the safety password, but we have the following information: the second -digit safing password is the first number of the first digit, the last 4th of the person in one unit is smaller than their first digit ...
Write a program that prints the number of number multiplying numbers 1 to 10
Write a function that receives the number of hours of employee work per month as a parameter and calculates the amount of employee salaries according to the formula below and returns each employee for 2 hours of work per month, per hour at 4 ...
Define a class of User that has a username, email and password and the following methods. Print: Print username and email in the output IS_Gmail: Check whether the user's email is Gmail and ...
برای استفاده از این بخش باید وارد حساب کاربریت بشی
ورود/ثبت نام If you don’t understand the exercise or can’t solve it for any reason, that’s completely
normal—don’t worry 😊
Try checking out easier exercises and reviewing different answers
submitted by others. Gradually, you can move on to more challenging exercises. Also, your answer
might be correct even if it’s different from others.