Og’irlik va vaznini solishtirish
a=float(input("Bo'yingizni kiriting (metr):"))
b=int( input("Vazningizni kiriting:") )
c = b / pow(a,2)
print(c)
Natija:
7
Funksiyaga oid misol
a=int(input("Sonni kiriting-"))
b=int(input("Sonni kiriting-"))
def funksiya(a,b):
print(a+b)
funksiya(a,b)
Natija:
Kalkulyator dasturi
from tkinter import*
import math
def btnClick(item):
tmp=str(text_input.get())
text_input.set(tmp+item)
def btnClear():
text_input.set("")
def btnEq():
s=eval(tmp)
text_input.set(s)
def ildiz():
tmp=math.pow(float(text_input.get(),1/2))
text_input.set(t)
root = Tk()
root.title("Kalkulator")
root.geometry("250x350")
text_input = StringVar()
e=Entry(root,width=20,borderwidth=5,textvariable=text_input)
e.place(width=220,height=40,relx=0.5,rely=0.1,anchor="c")
btn1=Button(root,text="7",background="green",foreground="black",padx="9", pady="8",command=lambda:btnClick("7"))
btn1.place(x=10, y=100)
btn2=Button(root,text="4",background="green",foreground="black",padx="9",pady="8",command=lambda:btnClick("4"))
btn2.place(x=10,y=150)
btn3=Button(root,text="1",background="green",foreground="black",padx="9", pady="8",command=lambda:btnClick("1"))
btn3.place(x=10, y=200)
btn4=Button(root,text="8",background="green",foreground="black",padx="9", pady="8",command=lambda:btnClick("8"))
btn4.place(x=50, y=100)
btn5=Button(root,text="5",background="green",foreground="black",padx="9", pady="8",command=lambda:btnClick("5"))
btn5.place(x=50, y=150)
btn6=Button(root,text="2",background="green",foreground="black",padx="9", pady="8",command=lambda:btnClick("2"))
btn6.place(x=50, y=200)
btn7=Button(root,text="9",background="green",foreground="black",padx="9", pady="8",command=lambda:btnClick("9"))
btn7.place(x=90, y=100)
btn8=Button(root,text="6",background="green",foreground="black",padx="9", pady="8",command=lambda:btnClick("6"))
btn8.place(x=90, y=150)
btn9=Button(root,text="3",background="green",foreground="black",padx="9", pady="8",command=lambda:btnClick("3"))
btn9.place(x=90, y=200)
btn10=Button(root,text="/",background="green",foreground="black",padx="9", pady="8",command=lambda:btnClick("/"))
btn10.place(x=130, y=100)
btn11=Button(root,text="*",background="green",foreground="black",padx="9", pady="8",command=lambda:btnClick("*"))
btn11.place(x=130, y=150)
btn12=Button(root,text="-",background="green",foreground="black",padx="9",pady="8",command=lambda:btnClick("-"))
btn12.place(x=130,y=200)
btn13=Button(root,text="0",background="green",foreground="black",padx="30",pady="8",command=lambda:btnClick("0"))
btn13.place(x=10,y=250)
btn14=Button(root,text=",",background="green",foreground="black",padx="9",pady="8",command=lambda:btnClick(","))
btn14.place(x=90,y=250)
btn15=Button(root,text="+",width=1,background="green",foreground="black",padx="9",pady="8",command=lambda:btnClick("+"))
btn15.place(x=130,y=250)
btn16=Button(root,text="%",width=1,background="green",foreground="black",padx="9",pady="8",command=lambda:btnClick("%"))
btn16.place(x=170,y=100)
btn17=Button(root,text="1/x",width=1,background="green",foreground="black",padx="9",pady="8",command=lambda:btnClick("1/x"))
btn17.place(x=170,y=150)
btn18=Button(root,text="=",background="green",foreground="black",padx="9",pady="32",command=lambda:btnEq())
btn18.place(x=170,y=200)
btn19=Button(root,text="c",background="green",foreground="black",padx="9",pady="8",command=lambda:btnClear())
btn19.place(x=210,y=100)
btn20=Button(root,text="(",background="green",foreground="black",padx="9",pady="8",command=lambda:btnClick("("))
btn20.place(x=210,y=150)
btn21=Button(root,text=")",background="green",foreground="black",padx="9",pady="8",command=lambda:btnClick(")"))
btn21.place(x=210,y=200)
btn22=Button(root,text="√",width=1,background="green",foreground="black",padx="9",pady="8",command=lambda:ildiz("√"))
btn22.place(x=210,y=250)
root.mainloop()
Do'stlaringiz bilan baham: |