Python programming codes
43 subscribers
25 photos
1 video
83 files
82 links
Uploading All programming codes are updating Daily
ask doubts in comment box 🎁☑️
Download Telegram
some important full forms
APL : Application Programming Interface

ALGOL : ALGOrithmic Language

PHP : Hypertext Preprocessor

JSP : Java Server Pages

J2EE : Java 2 Platform Enterprise Edition

ASP : Active Server Pages

SAP : System Analysis and Programming

XML : Extensible Markup Language

AJAX : Asynchronous JavaScript And XML

Wi-Fi : Wireless Fidelity

LISP : List Processing

APK : Android Application Package
python calculator source code

from tkinter import *
from math import *

root = Tk()
root.title("Calculator")
root.resizable(width=False, height=False)

screen = StringVar()
screen.set("0")

current = ""
power = ""

firstnum = str()
secondnum = str()
mathsign = str()

defxworking = False
percentt = False

def math_button_pressed():
if mathsign == '+':
button_plus.config(relief=SUNKEN)
if mathsign == '-':
button_minus.config(relief=SUNKEN)
if mathsign == '*':
button_multiply.config(relief=SUNKEN)
if mathsign == '/':
button_division.config(relief=SUNKEN)

def math_button_raised():
button_plus.config(relief=RAISED)
button_minus.config(relief=RAISED)
button_multiply.config(relief=RAISED)
button_division.config(relief=RAISED)

def is_int(num):
if int(num) == float(num):
return int(num)
else:
return float(num)

def number_pressed(butt):
global current, power, firstnum, secondnum

if mathsign == str() and defxworking == False:
current = current + str(butt)
screen.set(current)
firstnum = float(current)

elif mathsign != str() and defxworking == False:
math_button_raised()
current = current + str(butt)
screen.set(current)
secondnum = float(current)

elif mathsign == str() and defxworking == True:
power = power + str(butt)
current = current + str(butt)
screen.set(current)

elif mathsign != str and defxworking == True:
power = power + str(butt)
current = current + str(butt)
screen.set(current)
print(power)

def math_pressed(math):
global current, power, mathsign, firstnum, secondnum, defxworking, percentt

if mathsign == str() and defxworking == False and percentt == False and firstnum != str():
mathsign = str(math)
math_button_pressed()
current = ""

elif mathsign != str() and defxworking == False and percentt == False:
if mathsign == '+':
firstnum = round(float(firstnum + secondnum),6)
if mathsign == '-':
firstnum = round(float(firstnum - secondnum),6)
if mathsign == '*':
firstnum = round(float(firstnum * secondnum),6)
if mathsign == '/':
firstnum = round(float(firstnum / secondnum),6)
screen.set(is_int(firstnum))

mathsign = str(math)
math_button_pressed()
current = ""

elif mathsign != str() and defxworking == True and percentt == False:
if mathsign == '+':
firstnum = round(firstnum + secondnum ** int(power),6)
if mathsign == '-':
firstnum = round(firstnum - secondnum ** int(power),6)
if mathsign == '*':
firstnum = round(firstnum * (secondnum ** int(power)),6)
if mathsign == '/':
firstnum = round(firstnum / (secondnum ** int(power)),6)
defxworking = False
screen.set(is_int(firstnum))
defxworking = False
mathsign = str(math)
math_button_pressed()
power = ""
current = ""

elif defxworking and percentt == False:
firstnum = round(firstnum ** int(power), 6)
defxworking = False
screen.set(is_int(firstnum))
mathsign = str(math)
math_button_pressed()
power = ""
current = ""

elif percentt:
if mathsign == '+':
firstnum = round(float(firstnum + firstnum/100*secondnum),6)
if mathsign == '-':
firstnum = round(float(firstnum - firstnum/100*secondnum),6)
screen.set(is_int(firstnum))
percentt = False
mathsign = str(math)
math_button_pressed()
current = ""

def squareroot():
global firstnum, secondnum, mathsign, current

if mathsign == str():
firstnum = round(sqrt(firstnum),6)
screen.set(is_int(firstnum))

if mathsign != str():
if mathsign == '+':
firstnum = round(sqrt(firstnum + float(secondnum)),6)
if mathsign == '-':
firstnum = round(sqrt(firstnum - float(secondnum)),6)
if mathsign == '*':
firstnum = round(sqrt(firstnum * float(secondnum)),6)
if mathsign == '/':
firstnum = round(sqrt(firstnum / float(secondnum)),6)

screen.set(is_int(firstnum))
secondnum = str()
mathsign = str()
current = ""

def x():
global firstnum, secondnum, mathsign, current, defxworking

if mathsign == str():
current = str(is_int(firstnum)) + '^'
screen.set(current)
defxworking = True

elif mathsign != str():

current = str(is_int(secondnum)) + '^'
screen.set(current)
defxworking = True

def result():
global firstnum, secondnum, mathsign, current, power, defxworking, percentt
if defxworking == False and percentt == False:
if mathsign == '+':
firstnum = round(float(firstnum + secondnum),6)
if mathsign == '-':
firstnum = round(float(firstnum - secondnum),6)
if mathsign == '*':
firstnum = round(float(firstnum * secondnum),6)
if mathsign == '/':
firstnum = round(float(firstnum / secondnum),6)
screen.set(is_int(firstnum))

if mathsign == str() and defxworking == True and percentt == False:
firstnum = round(firstnum ** int(power),6)
defxworking = False
screen.set(is_int(firstnum))

if mathsign != str() and defxworking == True and percentt == False:
if mathsign == '+':
firstnum = round(firstnum + secondnum ** int(power),6)
if mathsign == '-':
firstnum = round(firstnum - secondnum ** int(power),6)
if mathsign == '*':
firstnum = round(firstnum * (secondnum ** int(power)),6)
if mathsign == '/':
firstnum = round(firstnum / (secondnum ** int(power)),6)
defxworking = False
screen.set(is_int(firstnum))


if defxworking == False and percentt == True:
if mathsign == '+':
firstnum = round(float(firstnum + firstnum/100*secondnum),6)
screen.set(is_int(firstnum))
percentt = False
if mathsign == '-':
firstnum = round(float(firstnum - firstnum/100*secondnum),6)
screen.set(is_int(firstnum))
percentt = False

if defxworking == False and mathsign == '*' or '/' and percentt == True:
clear()

mathsign = str()
current = ""
power = ""

def clear():
global current, firstnum, secondnum, mathsign, power, defxworking, percentt

screen.set(0)
current = ""
power = ""
firstnum = str()
secondnum = str()
mathsign = str()
defxworking = False
math_button_raised()
percentt = False

def percent():
global firstnum, secondnum, current, percentt

current = str(is_int(secondnum)) + '%'
screen.set(current)
percentt = True



# Widgets

calculation = Entry(root, textvariable = screen, font=("Verdana", 15, ), bd = 12,
insertwidth=4, width=14, justify=RIGHT)
calculation.grid(columnspan=4)
# Numbers
button1 = Button(root, text='1', command=lambda: number_pressed(1), bg="gainsboro",
bd=3, padx=12, pady=5, font=("Helvetica", 14, "bold"))
button1.grid(row=2, column=0, sticky=W)
button2 = Button(root, text='2', command=lambda: number_pressed(2), bg="gainsboro",
bd=3, padx=12, pady=5, font=("Helvetica", 14, "bold"))
button2.grid(row=2, column=1, sticky=W)
button3 = Button(root, text='3', command=lambda: number_pressed(3), bg="gainsboro",
bd=3, padx=12, pady=5, font=("Helvetica", 14, "bold"))
button3.grid(row=2, column=2, sticky=W)
button4 = Button(root, text='4', command=lambda: number_pressed(4), bg="gainsboro",
bd=3, padx=12, pady=5, font=("Helvetica", 14, "bold"))
button4.grid(row=3, column=0, sticky=W)
button5 = Button(root, text='5', command=lambda: number_pressed(5), bg="gainsboro",
bd=3, padx=12, pady=5, font=("Helvetica", 14, "bold"))
button5.grid(row=3, column=1, sticky=W)
button6 = Button(root, text='6', command=lambda: number_pressed(6), bg="gainsboro",
bd=3, padx=12, pady=5, font=("Helvetica", 14, "bold"))
button6.grid(row=3, column=2, sticky=W)
button7 = Button(root, text='7', command=lambda: number_pressed(7), bg="gainsboro",
bd=3, padx=12, pady=5, font=("Helvetica", 14, "bold"))
button7.grid(row=4, column=0, sticky=W)
button8 = Button(root, text='8', command=lambda: number_pressed(8), bg="gainsboro",
bd=3, padx=12, pady=5, font=("Helvetica", 14, "bold"))
button8.grid(row=4, column=1, sticky=W)
button9 = Button(root, text='9', command=lambda: number_pressed(9), bg="gainsboro",
bd=3, padx=12, pady=5, font=("Helvetica", 14, "bold"))
button9.grid(row=4, column=2, sticky=W)
button0 = Button(root, text='0', command=lambda: number_pressed(0), bg="gainsboro",
bd=3, padx=12, pady=5, font=("Helvetica", 14, "bold"))
button0.grid(row=5, column=0, sticky=W)
button_float = Button(root, text='.', command=lambda: number_pressed('.'), bg="gainsboro",
bd=3, padx=15, pady=5, font=("Helvetica", 14, "bold"))
button_float.grid(row=5, column=1)

# Math signs
button_plus = Button(root, text='+', command=lambda: math_pressed('+'), bg="gray70",
bd=3, padx=11, pady=5, font=("Helvetica", 14, "bold"))
button_plus.grid(row=2, column=3, sticky=W)
button_minus = Button(root, text='-', command=lambda: math_pressed('-'), bg="gray70",
bd=3, padx=11, pady=4, font=("Verdana", 14, "bold"))
button_minus.grid(row=3, column=3, sticky=W)
button_multiply = Button(root, text='*', command=lambda: math_pressed('*'), bg="gray70",
bd=3, padx=13, pady=5, font=("Helvetica", 14, "bold"))
button_multiply.grid(row=4, column=3, )
button_division = Button(root, text='/', command=lambda: math_pressed('/'), bg="gray70",
bd=3, padx=14, pady=5, font=("Helvetica", 14, "bold"))
button_division.grid(row=5, column=3, )
button_equal = Button(root, text='=', command=lambda: result(), bg='orange',
bd=3, padx=12, pady=5, font=("Arial", 14))
button_equal.grid(row=5, column=2, )

button_percent = Button(root, text='%', command=lambda: percent(), bg="gray70",
bd=3, padx=8, pady=5, font=("Helvetica", 14, "bold"))
button_percent.grid(row=1, column=3, )

button_clear = Button(root, text='C', command=lambda: clear(), bg='gray70',
bd=3, padx=11, pady=5, font=("Helvetica", 14))
button_clear.grid(row=1, column=0)
button_sqrt = Button(root, text='√', command=lambda: squareroot(), bg="gray70",
bd=3, padx=12, pady=5, font=("Helvetica", 14, "bold"))
button_sqrt.grid(row=1, column=1, sticky=W)
button_x = Button(root, text='x^y', command=lambda: x(), bg="gray70",
bd=3, padx=6, pady=5, font=("Helvetica", 14))
button_x.grid(row=1, column=2, sticky=W)

root.mainloop()
#calculate the chicken rate
n_Gram = int(input("enter the weigth of grams : "))

cost = int(input("enter the cost value: "))
one_GramCost = cost/1000

print("the {} grams weight is {} ".format(n_Gram,one_GramCost*n_Gram))
#turtleprograms
program 01
source code

input:

#Square Spiral
from turtle import*

for i in range(20):
forward(i*10)
right(90)

done()


output:
#turtleprograms
program 01
source code

input:

#star program

from turtle import*

for i in range(5):
forward(100)
right(144)

done()

output:
#turtleprograms
program 01
source code

input:

#Spirograph program

from turtle import*

speed(200)
for i in range(72):
circle(100)
right(5)

done()

output:
#turtleprograms
program 01
source code

input:

#Sunburst program

from turtle import*

for i in range(36):
forward(50)
backward(100)
right(10)
done()


output:
----------------------------------
Python Basic programs starting to advanced programs all uploading
------pyclsinclg------
#forloop

#example - 1 : To print characters present in tge given string

s = "Sweety my world website"

for i in s:
print(i,end=" ")
print(i)
#forloop
#example - 2 : To print characters present in string indexwise

x = input("Enter the name : ")
i = 0
for n in x:
print(n,"+ve index is ",i,"-ve index is ",i-len(x))
i += 1
#forloop
#example - 3 : To print Sweety My World

for i in range(10):
print("Sweety My World")
#forloop
#example - 4 : To display numbers from 0 to 25

for x in range(26):
print(x)
#forloop
#example - 5 : To display odd numbers from 0 to 25
for i in range(26):
if (i%2 != 0):
print(i)
#forloop
#example - 6 : To display odd numbers from 25 to 0 descending order

for i in range(25,0,-1):
print(i)
#nested_loop_example_1 :
""" To print all rows and columns equals with star pattren

i is row and j is column"""

#method_1
for i in range(1,6):
for j in range(1,6):
print("*",end=" ")
print()

print()

#method_2
for i in range(5):
print("* "*5)
#nested_loop_example_2 :
""" To print all rows and columns + 1 with star pattren

#Right half pyramid

i is row and j is column"""

#method_1
for i in range(0,6):
for j in range(i+1):
print("*",end=" ")
print()

print()

#metgod_2
for i in range(6):
for j in range(i+1):
print("*",end=" ")
print()

print()

#method_3
for i in range(6):
print("* "*(i+1))

print()

#method_4
def pattern(n):
k = 2 * n - 2
for i in range(0, n):
for j in range(0, k):
print(end="")
k = k - 2
for j in range(0, i + 1):
print("* ", end="")
print(" ")

pattern(6)

print()
#nested_loop_example_3 :
""" To print reverse all columns and rows - 1 with star pattren

i is row and j is column"""

#method_1


#method_2 (shortcut method)
for i in range(5):
print(" "*i,"* "*(5-i))
#nested_loop_example_4 :
""" To print left half pyramid with star pattren program

i is row and j is column"""

#method_1


#method_2 (shortcut method)
n = int(input("Enter the value: "))
for i in range(n):
print(" "*(n-(i+1)),"* "*(i+1))