## Execute Python Online

```# Hello World program in Python
javascript:;
print "fuck you world,fsociety"
clear
```

## Solutions to a quadratic equation using Python

```# quadratic.py
#    A program that computes the real roots of a quadratic equation.
#    Illustrates use of the math library.
#    Note: This program crashes if the equation has no real roots.

import cmath  # Makes the math library available.

print("This program finds the real solutions to a quadratic")

a=-2
b=5
c=1

discRoot = cmath.sqrt( a * c)
root1 = (-b + discRoot)
root2 = (-b - discRoot)

print("The solutions are:", root1, root2 )```

## Assignment

```"""create 10 objects"""
class Employee:
'Common base class for all employees'

from operator import itemgetter

def __init__(self, empId,name,age,Dept):
self.EmpId = empId
self.Name=name
self.Age=age
self.Department=Dept

def set_EmpId(self, EmpId):
self.EmpId = EmpId

def set_Name(self, Name):
self.Name = Name

def set_Age(self, Age):
self.Age = Age

def set_Department(self, Department):
self.Department = Department

def get_EmpId(self):
return self.EmpId

def get_Name(self):
return self.Name

def get_Age(self):
return self.Age

def get_Department(self):
return self.Department

emp1 = Employee("127H8", "Hema", 23, "Development")
emp2 = Employee("127E5", "Satya", 29, "Marketing")
emp3 = Employee("127M13", "Sindhu", 30, "Testing")
emp4 = Employee("127A1", "Rakesh", 35,"Support")
emp5 = Employee("127S19", "Divya", 22,"Maintance")
emp6 = Employee("127A12", "Priya", 18,"Support")
emp7 = Employee("127T20", "Sankar", 12,"Development")
emp8 = Employee("127Y25", "Navya", 45,"Testing")
emp9 = Employee("127A13", "USha", 24,"Marketing")
emp10 = Employee("127L12", "Venkat",33, "Development")

""" store a 10 objectsin dictionary key"""
def __str__(self):
return str(self.__class__) + ": " + str(self.__dict__)
emp_list = [emp1,emp2,emp3,emp4,emp5,emp6,emp8,emp9,emp10]
emp_dict = {}
for i in emp_list:
emp_dict[i.get_EmpId()] = i
print(__str__(i))

# """ sorting"""
# print("************")
# for k in sorted(emp_dict,key=emp_dict.get(i),reverse=True):
#   print(k)

# f=open("file.txt")
# for k,v in emp_dict.items():
#     f.write(k,v)
# f.close()```

## Assigning Values to Variables examle

```#assignment of python
class employee:

def setdata(self):
num_employee = int(input("Please enter number of emloyees:"))
print ("you entered %s employees" %num_employee)
employee_info = {}
employee_data = ['emp_id ' ,'emp_age  ', 'emp name  ', 'emp dept  ']
for i in range(0,num_employee):
emp_id = input("emd id  :")
employee_info[emp_id] = {}
for entry in employee_data:
employee_info[emp_id][entry] = str(input(entry))

for (key, value) in employee_info.items() :
print(key , " : ", value )

for key in sorted(employee_info.keys()):
print("%s: %s" % (key, employee_info[key]))

def main():
emp = employee()
emp.setdata()

if __name__=="__main__":
main()

f = open("filepath",'w')
f.write( "\n");

# Close opend file
f.close()```

## Calculate needed money to last lifetime

```year = 2019
salary = 120000
totalAmountNeeded = 0
while year < 2120:
totalAmountNeeded += salary
salary += salary * .025
if year < 2030:
print("Year:", year)
print("Salary:", salary)
year += 1

print(totalAmountNeeded)
```

## Matrix using Numpy (Python)

```import numpy as np

a = np.arange(5)
b = np.arange(9).reshape(3, 3)

print(np.exp(a))

print(b+1)```

## Python Calling a Function

```"""create 10 objects"""
class Employee:
'Common base class for all employees'

from operator import itemgetter

def __init__(self, EmpId,age,name,Dept):
self.EmpId = EmpId
self.Age=age
self.Name=name
self.Department=Dept

def set_EmpId(self, EmpId):
self.EmpId = EmpId

def set_Age(self, Age):
self.Age = Age

def set_Name(self, Name):
self.Name = Name

def set_Department(self, Department):
self.Department = Department

def get_EmpId(self):
return self.EmpId

def get_Age(self):
return self.Age

def get_Name(self):
return self.Name

def get_Department(self):
return self.Department

emp1 = Employee("127034", 22,"Hma", "Python")
emp2 = Employee("124",    212,"He", "Pyt")
emp3 = Employee("12703", 12,"Hema", "Pyton")
emp4 = Employee("12708678", 202,"Hema", "hon")
emp5 = Employee("1270355", 223,"Hema", "Pthon")
emp6 = Employee("12703466", 20,"Hema", "Pyth")
#emp7 = Employee("127034", 02,"Hema", "Pthon")
emp8 = Employee("12703466", 222,"Hema", "Pyton")
emp9 = Employee("12703477", 232,"Hema", "Pyon")
emp10 = Employee("12703488", 225,"Hema", "Pthon")
""" store a 10 objectsin dictionary key"""
def __str__(self):
return str(self.__class__) + ": " + str(self.__dict__)
emp_list = [emp1,emp2,emp3,emp4,emp5,emp6,emp8,emp9,emp10]
emp_dict = {}
for i in emp_list:
emp_dict[i.get_EmpId()] = i
print(__str__(i))
""" sorting"""
print("************")
for k in sorted(emp_dict,key=emp_dict.get(i),reverse=True):
print(k)

# f=open("file.txt")
# for k,v in emp_dict.items():
#     f.write(k,v)
# f.close()

```

## Stack POP and PUSH operation using Python

```# Hello World program in Python

print "Hello World!\n"

class Stack:

def __init__(self):
self.items=[]

def isEmpty(self):
self.items==[]

def push(self,value):
self.items.append(value)

def pop(self):

return self.items.pop()

def peek(self):
return self.items[len(self.items)-1]

def size(self):
return len(self.items)

def __str__(self):
return  str(self.items)

st=Stack()

st.push(5)
st.push(6)

print st.peek()

st.pop()

print st

st.pop()

print(st)
```

## Around, sort and divide using NumPy

```# Hello World program in Python

import numpy as np

pi = np.pi

print(pi)

a2 = np.array([153.952, 299.154, 436.185, 565.584, 687.845, 803.428, 912.758, 1114.21, 1207.04, 1295.02, 1378.47, 1457.64, 1532.79, 1604.17, 1671.98, 1736.44, 1797.73, 1856.05])

a1 = np.array([2980.3125, 2814.73958333, 2649.16666667, 2483.59375, 2318.02083333, 2152.44791667, 1986.875, 1821.30208333, 1655.72916667, 1490.15625, 1324.58333333, 1159.01041667, 993.4375, 827.86458333, 662.29166667, 496.71875, 331.14583333, 165.57291667])

print(a1)

a1 = np.around([a1], decimals=3)

print(a1)

a1 = np.sort(a1)

print(a1)

erg = np.divide(a2, a1)

print(erg)```

## Matematika-11

```import numpy as n

G1=[0,2.3,4.5,6.,8.7,9.5]
G2=[0.,1.9,3.8,5.,6.8,8.]
G3=[0,4,5,5.4,7.2,9]

print 'Pripustimo sho vsi resursi v tretyogo pidpriemstva'

for ii in range(6):
print 'delta3=',ii,'C3=',G3[ii]

print 'Viberemo optimalniy rozpodil mizh 2 i 3'
D23={}
AUX23={}
for ii in range(6):
D23[ii]=[]
for jj in range(ii+1):
for kk in range(ii+1):
if jj+kk==ii:
D23[ii].append(G2[jj]+G3[kk])
AUX23[G2[jj]+G3[kk]]=str(jj)+' '+str(kk)
OPT23=[]
for ii in range(6):
print 'delta23=',ii,'C23=',max(D23[ii])
OPT23.append(max(D23[ii]))

print 'Viberemo optimalniy rozpodil mizh pershim i inshimi...'

D={}
AUX={}
for ii in range(6):
D[ii]=[]
for jj in range(ii+1):
for kk in range(ii+1):
if jj+kk==ii:
D[ii].append(G1[jj]+OPT23[kk])
AUX[G1[jj]+OPT23[kk]]=str(jj)+' '+str(kk)

ch1= AUX[max(D[5])].split()[0]
OPTIMUM=max(D[5])
print 'maximalniy pributok= ',OPTIMUM
print 'pershe pidpriyemstvo otrimalo ',ch1

ch23= AUX23[OPTIMUM-G1[int(ch1)]]
print 'druge pidpriyemstvo otrimalo', ch23.split()[0]
print 'tretye pidpriyemstvo otrimalo', ch23.split()[1]

PEREVIRKA=0.
print "perevirimo pereborom usih variantiv..."
for ii in range(6):
for jj in range(6):
for kk in range(6):
if (ii+jj+kk)==5:
temp=G1[ii]+G2[jj]+G3[kk]
if temp>PEREVIRKA:
PEREVIRKA=temp
print 'nove maksimalne znachennya=',temp,ii,jj,kk

```