تمرین برنامه نویسی؛ با کدبزن!

منبع جامع سوالات و تمرینات برنامه نویسی

7
+1
+1
+1

کلاس ماشین حساب

Amirhn آسان 9/ دانلود 1224 بازدید

کلاسی بنویسید که دو عدد دریافت کند و متدهای جمع و تفریق و ضرب و تقسیم برای آن قابل فراخوانی باشد. با فراخوانی هر متد، محاسبات لازمه انجام شود و نتیجه در برگردانده شود

23 جواب

نمیتونم این تمرین رو حل کنم!
0
class Calculater:
    
    def __init__(self, num1, num2):
        self.num1 = num1
        self.num2 = num2

    def sum(self):
        print(f"{self.num1} + {self.num2} = {int(self.num1) + int(self.num2)}")

    def subtraction(self):
        print(f"{self.num1} - {self.num2} = {int(self.num1) - int(self.num2)}")

    def multiplication(self):
        print(f"{self.num1} * {self.num2} = {int(self.num1) * int(self.num2)}")

    def division(self):
        print(f"{self.num1} / {self.num2} = {int(self.num1) / int(self.num2)}")

i = input('Number = ')
j = input('Number = ')

num = Calculater(i, j)

num.sum()
num.subtraction()
num.multiplication()
num.division()
Pooria08 دانلود Python
0
class MashinHesab:
  def khat():
    print('--------------------------------')


  def jam():
    a = int(input("num: "))
    b = int(input('num: '))
    MashinHesab.khat()
    return a + b


  def tafrigh():
    a = int(input('num: '))
    b = int(input('num: '))
    MashinHesab.khat()
    return a - b


  def zarb():
    a = int(input('num: '))
    b = int(input('num: '))
    MashinHesab.khat()
    return a * b


  def taghsim():
    a = int(input('num: '))
    b = int(input('num: '))
    MashinHesab.khat()
    return a / b



while 1:
  MashinHesab.khat()
  javab = input('choose: 1.jam 2.tafrigh 3.zarb 4.taghsim: \n')
  if javab == '1':
    print(MashinHesab.jam())


  elif javab == '2':
    print(MashinHesab.tafrigh())


  elif javab == '3':
    print(MashinHesab.zarb())


  elif javab == '4':
    print(MashinHesab.taghsim())
Younes دانلود Python
0
class calculator:
    def __init__(self,a,b):
        self.a = a
        self.b = b
    def sum(self):
        return satl.a + satl.b
    def Differentiation(self):
        return satl.a - satl.b
    def multiplication(self):
        return satl.a*satl.b  
    def Division(self):
        return satl.a / satl.b
  
a = 10
b = 5 
satl = calculator(a,b)
print(satl.Division())      
Knowledgebiome دانلود Python
0
class Zarb():
    i = int(input("num: "))
    j = int(input("num2: "))
    print("sum:       ",i + j)
    print("minus:     ",i - j)
    print("beat:      ",i * j)
    print("Division   ",float(i / j))
    print("left over: ",i % j)
print(Zarb())    
  
Amirhosein دانلود Python
0
class Z:
    def __init__(self,x,y):
        self.x=x
        self.y=y
       
    def a(self):
        q1=input('your work?  + -  * /\n  ')
        if q1=='+':print(self.x+self.y)
        if q1=='-':print(self.x-self.y)
        if q1=='*':print(self.x*self.y)
        if q1=='/':print(self.x/self.y)

x=input("enter the value of x :\n")
y=input ("enter the value of y :\n")
nums=Z(int(x),int(y))        

nums.a()
        

Hadiozan20 دانلود Python
0
class calculator:
  def __init__(self, num, num2):
    self.num = num
    self.num2= num2
    

  def collect(self):
    collect =self.num + self.num2
    return collect
  
  def low_of(self):
    if self.num>self.num2:
      low_of = self.num-self.num2
    else:
      low_of = self.num2-self.num
    return low_of
  
  def division(self):
    if self.num>self.num2:
      if self.num%self.num2==0:
        return self.num//self.num2
      else:
        return self.num/self.num2
    else:
      if self.num2%self.num==0:
        return self.num2//self.num
      else:
        return self.num2/self.num
      
  def zarb(self):
    zarb = self.num*self.num2
    return zarb
try: 
  num= float(input('num1: '))
  num2= float(input('num2: '))

  c = calculator(num,num2)
  print("collect:", c.collect())
  print("low_of:", c.low_of())
  print("division:", c.division())
  print("zarb: ",c.zarb())
except:
  print("error")
کاربر 1393 دانلود Python
0
class Calculator:
    def __init__(self,a,b):
        a.self = a
        b.self = b
    def adition(a,b):
        u1= a + b
        return u1
    def subtraction(a,b):
        u2 = a - b
        return u2
a = float(input("enter your number;"))
b = float(input("enter another number:"))
Calculator(a.b)
Negar دانلود Python
0
class SimpleCalculator : 
    def __init__(self,num1,num2) : 
        self.num1=num1
        self.num2=num2
    
    def jam(self) : 
        print(self.num1+self.num2)
        
    def tafrigh(self) :
        print(self.num1-self.num2)
        
    def zarb(self) : 
        print(self.num1*self.num2)
        
    def taghsim(self) :
        print(self.num1/self.num2)
Soheyl دانلود Python
0
#ماشین حساب
from tkinter import *

calculation = ""

def add_to_calculation(symbol):
    global calculation
    calculation += str(symbol)
    text_result.delete(1.0, 'end')
    text_result.insert(1.0, calculation)

def evaluate_calculation():
    global calculation
    try:
        calculation = str(eval(calculation))
        text_result.delete(1.0, 'end')
        text_result.insert(1.0, calculation)
    except:
        clear_fields()
        text_result.insert(1.0, "Error")

def clear_fields():
    global calculation
    calculation = ""
    text_result.delete(1.0, 'end')

root = Tk()
root.minsize(300,275)
root.maxsize(300,275)
root.title('calculator')

text_result = Text(root, height=2, width=16, font=('Arial', 24))
text_result.insert(1.0, "ARMAN_KHALILI")
text_result.grid(columnspan=5)

btn_1 = Button(root, text='1', command=lambda: add_to_calculation(1), width=5, font=("Arial", 14))
btn_1.grid(row=2, column=1)
btn_2 = Button(root, text='2', command=lambda: add_to_calculation(2), width=5, font=("Arial", 14))
btn_2.grid(row=2, column=2)
btn_3 = Button(root, text='3', command=lambda: add_to_calculation(3), width=5, font=("Arial", 14))
btn_3.grid(row=2, column=3)
btn_4 = Button(root, text='4', command=lambda: add_to_calculation(4), width=5, font=("Arial", 14))
btn_4.grid(row=3, column=1)
btn_5 = Button(root, text='5', command=lambda: add_to_calculation(5), width=5, font=("Arial", 14))
btn_5.grid(row=3, column=2)
btn_6 = Button(root, text='6', command=lambda: add_to_calculation(6), width=5, font=("Arial", 14))
btn_6.grid(row=3, column=3)
btn_7 = Button(root, text='7', command=lambda: add_to_calculation(7), width=5, font=("Arial", 14))
btn_7.grid(row=4, column=1)
btn_8 = Button(root, text='8', command=lambda: add_to_calculation(8), width=5, font=("Arial", 14))
btn_8.grid(row=4, column=2)
btn_9 = Button(root, text='9', command=lambda: add_to_calculation(9), width=5, font=("Arial", 14))
btn_9.grid(row=4, column=3)
btn_0 = Button(root, text='0', command=lambda: add_to_calculation(0), width=5, font=("Arial", 14))
btn_0.grid(row=5, column=2)
btn_plus = Button(root, text='+', command=lambda: add_to_calculation('+'), width=5, font=("Arial", 14))
btn_plus.grid(row=2, column=4)
btn_minus = Button(root, text='-', command=lambda: add_to_calculation('-'), width=5, font=("Arial", 14))
btn_minus.grid(row=3, column=4)
btn_mul = Button(root, text='*', command=lambda: add_to_calculation('*'), width=5, font=("Arial", 14))
btn_mul.grid(row=4, column=4)
btn_div = Button(root, text='/', command=lambda: add_to_calculation('/'), width=5, font=("Arial", 14))
btn_div.grid(row=5, column=4)
btn_open = Button(root, text='(', command=lambda: add_to_calculation('('), width=5, font=("Arial", 14))
btn_open.grid(row=5, column=1)
btn_close = Button(root, text=')', command=lambda: add_to_calculation(')'), width=5, font=("Arial", 14))
btn_close.grid(row=5, column=3)
btn_clear = Button(root, text='C', command=clear_fields, width=11, font=("Arial", 14))
btn_clear.grid(row=6, column=1, columnspan=2)
btn_equals = Button(root, text='=', command=evaluate_calculation, width=11, font=("Arial", 14))
btn_equals.grid(row=6, column=3, columnspan=2)
root.mainloop()
کاربر 2217 دانلود Python
0
class Calculator :
    def __init__ ( self , x , y ) -> None :
        self . x = x
        self . y = y
        
    def Mutiply ( self ) :
        return self . x * self . y
    
    def Divide ( self ) :
        return self . x / self . y
    
    def Plus ( self ) :
        return self . x + self . y
    
    def Minus ( self ) :
        return self . x - self . y
    
Kian1390 دانلود Python
<< صفحه قبل 1 2 3 صفحه بعد >>

ارسال جواب

/* کداتو توی این بخش بنویس
فرقی نمیکنه چه زبان برنامه نویسی باشه، همرو پشتیبانی میکنیم :)
البته قبلش این سه خط رو پاک کن */
                    
  • لطفا جواب های تکراری ارسال نکن
  • قبل از ارسال، جوابت رو داخل یک کد ادیتور مثل vscode بنویس و بعد اینجا Paste کن
  • جواب های ارسالی، پس از بررسی کوتاهی، ویرایش میشن و در سایت نمایش داده میشن
  • ارسال جواب حق مادی یا معنوی برای ارسال کننده ایجاد نمیکند و تمام حقوق برای سایت کدبزن محفوظ است

تمرینات مرتبط

تشخیص با استفاده از هوش مصنوعی
×
×
بستن