0% found this document useful (0 votes)
7 views7 pages

Python Codes

Practice Python codes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views7 pages

Python Codes

Practice Python codes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

!.

Even Odd Replacement

#Take a list from the user

#If the number is even shift element 2 places to the right and if it is last, replace it with the first.

#If element is odd replace with adjacent element and if last replace with first

l=list(input("Enter the list"))

a=len(l)

for i in l:

x=int(i)

z=l.index(i)

if z==a:

l[z]=l[0]

print(l)

if x%2==0:

if z+1<a:

m=l[z+2]

l[z+2]=l[z]

l[z]=m

print(l)

qq=l[0]

l[0]=l[-1]

l[-1]=qq

print(l)

if x%2!=0:

if z+1<a:

m=l[z+1]

l[z+1]=l[z]

l[z]=m
print(l)

qq=l[0]

l[0]=l[-1]

l[-1]=qq

print(l)

print(l)

3.Ascending List

k=eval(input("enter number of elements"))

l=[]

for i in range(1,k+1):

n=eval(input("enter the number"))

l.append(n)

for i in range(1,k+1):

for i in l:

m=l.index(i)

if m!=0:

if l[m-1]>l[m]:

g=l[m]

l[m]=l[m-1]

l[m-1]=g

elif m==k:

if l[m]>l[0]:

t=l[0]

l[0]=l[m]

l[m]=t

print(l)

4.Dictionary Creation
#n={"a":"water","b":"wyvern"}

#print(n)

n=eval(input("number of data entries"))

m=0

d={}

while m!=n:

a=input("enter key name")

b=input("enter value")

d[a]=b

m=m+1

print(d)

5.Manager Employee Database

#n-managers id--->wn-salesperson

#display the name of the salesperson who is having the max monthly collection under all the
managers

#also count those salespersons whose name does not contain the alphabets A,E

#push all the salesperson id onto the stat namely stack

n=int(input("no. of managers"))

z={}

f={}

q=[]

x=0

dd=[]

nn=[]

iii=[]

stack=[]

while x!=n:

x=x+1
mid=input("enter manager id")

q.append(mid)

nsp=int(input("number of salesperson"))

for i in range(1,nsp+1):

salid=input("enter salesperson id")

name=input("enter salesperson name")

nn.append(name)

adress=input("city")

mc=input("enter monthly collection")

dd.append(mc)

z.update({"salesperson id":salid,"name":name,"monthly collection":mc,"adress":adress})

q.append(z)

z={}

o=max(dd)

k=dd.index(o)

f=str(nn[k])

print(q)

print("The salesperson with highst collection is",f)

for i in nn:

j=str(i)

if 'a' not in j and 'e' not in j:

iii.append(j)

print(len(iii))

if 'a' not in f and 'e' not in f:

stack.append(f)

print("The salesperson satisfying all criteria:",f)

6.input two strings, if string 1 is contained in srtring2 then create a 3rd sting with first 4 characters
of string 2 added to the word restore
s1=input("enter string1:")

s2=input("enter string2:")

x=s2[0:4]

if s1 in s2:

s3=(x+"restore")

print(s3)

7.

#repeatedly ask the user to enter a team name and how many games the team has won and lost

#store this information in dictionary form where the keys are the teamnames and the values are
list of

#the form [wins,losses]

#allow the user to enter a team name and print out the team's winning percentage

#create a list whose entries are the number of wins of each team

#a list of all those teams that have winning records

n=eval(input("enter number of teams"))

wl=[]

z={}

teams=[]

winps=[]

winss=[]

winrecords=[]

for i in range(1,n+1):

team=input("enter team name:")

teams.append(team)

wins=int(input("enter wins"))

winss.append(wins)

losses=int(input("enter losses"))
wl.append(wins)

wl.append(losses)

winp=(wins/(wins+losses))*100

winps.append(winp)

z.update({team:wl})

if wins>1:

winrecords.append(team)

print("list of wins",winss)

print("win records",winrecords)

print(z)

k=input("enter team name to find win percentage:")

l=teams.index(k)

m=winps[l]

print(m)

8.

#program to check if each element in the first half of a touple is less than the sum of all even
number from the second half of the touple.

t=tuple(input("enter the elements"))

x=len(t)

print("x",x)

if x%2==0:

y=int(x/2)

else:

y=int((x+1)/2)

print("y",y)

z=0

for i in t[y:x]:

d=int(i)
if d%2==0:

z+=d

print(z)

for j in t[0:y]:

m=int(j)

if m<z:

print(j,"is smaller than sum of even numbers:",z)

else:

print(j,"is larger than sum of even numbers:",z)

You might also like