0% found this document useful (0 votes)
0 views3 pages

Codes

The document contains various Python programs that perform tasks such as calculating the median and mode of a list, finding the minimum and maximum values within a specified range, replacing values in a list, calculating cumulative sums, and managing employee data in dictionaries. It also includes functionalities for counting characters in a string, converting numbers to words, identifying overlapping keys between dictionaries, and checking if one dictionary is contained within another. Additionally, it features a simple user authentication system using usernames and passwords stored in a dictionary.

Uploaded by

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

Codes

The document contains various Python programs that perform tasks such as calculating the median and mode of a list, finding the minimum and maximum values within a specified range, replacing values in a list, calculating cumulative sums, and managing employee data in dictionaries. It also includes functionalities for counting characters in a string, converting numbers to words, identifying overlapping keys between dictionaries, and checking if one dictionary is contained within another. Additionally, it features a simple user authentication system using usernames and passwords stored in a dictionary.

Uploaded by

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

MEDIAN

lst = eval(input ("Enter the List :- "))


feq = []
for i in lst :
feq += [lst.count(i)]
feq.sort()
for i in lst :
if feq[-1] == lst.count(i):
print("Mode = ",i)
Break
MODE
lst = eval(input ("Enter the List :- "))
feq = []
for i in lst :
feq += [lst.count(i)]
feq.sort()
for i in lst :
if feq[-1] == lst.count(i):
print("Mode = ",i)
Break
Min and max range
lst = eval(input("Enter a list :-"))
start = int(input("Enter starting index :-"))
stop = int(input("Enter stoping index :-"))
print( "Max :-", max( lst [ start : stop ] ) )
print("Min :- ", min( lst [ start : stop ] ))

Ask the user to enter a list containing numbers between 1 and 12 then replace all of the entries in the list that are greater than 10
with 10

a = eval(input ("Enter the list ="))


for i in range(len(a)) :
if a[i] > 10 :
a[i] = 10
print ("New list ",a)

Cumulative sum of a list [a, b, c...] is defined as [a, a + b, a + b + c, ...). Write a program to input a list of number and then create
another list from this list that contains cumulative sum of numbers in list1.

lst = eval(input ("Enter the List :- "))


lst1 = [ ]
sum = 0
for i in lst :
sum += i
lst1 += [ sum ]
print(lst1)

DICTIONARY
Write a program to enter names of employees and their salaries as input and store them in a dictionary.
dic = { }
while True :
name = input("Enter employee name :-")
sl = int(input("Enter employee salary :-"))
dic[ name] = sl
user = input("Do you want to quit then enter yes :-")
if user == "yes" :
Break
print(dic)
Count no of character
string = input("Enter String :- ")
dic = { }
for i in string :
dic [ i ] = string.count( i )

print(dic)
Number to word
num = input ("Enter a number :- ")
dic = { "0" : "Zero" , "1":"One" , "2" : "Two" , "3" : "Three" , "4" : "Four" , "5" : "Five" , "6" : "Six" , "7" : "Seven" , "8" : "Eight" , "9" :
"Nine"}

for i in num :
print( dic[ i ], end = " ")

Write a program that lists the over lapping keys of the two dictionaries if a key of d1 is also a key of d2, the list it.

d1 = eval(input("Enter first dictionary = "))


d2 = eval(input("Enter second dictionary = "))
lst1 = (d1.keys() )
lst2 = (d2.keys() )
lst = [ ]
for i in lst1 :
for j in lst2 :
if i == j :
lst += [ i ]
print("Over lapping keys are ",lst )

If two same values hav diff keys


dic = eval(input("Enter a dictionary = "))
count = 0
lst = list (dic.values())

for i in lst :
a = lst.count(i)
if a > 1 :
count += a
for j in lst :
if i == j :
lst.remove( j )

if count == 0 :
print( "no values are same " )
else :
print( count,"values are same ")
If one dict is in another
dic1 = eval(input("Enter first dictionary :-"))
dic2 = eval(input("Enter second dictionary :-"))

count = 0
for i in dic1 :
for j in dic2 :
if i == j :
count += 1

if count == len(dic1):
print("Then d1 is contained in d2.")
else :
print("Then d1 is not contained in d2.")

A dictionary D1 has values in the form of lists of numbers. Write a program to create a new dictionary D2 having same keys as D1
but values as the sum of the list elements

dic1 = eval(input("Enter dictionary :-"))


dic2 = {}

for i in dic1 :
lst = dic1[ i ]
sum_of_num = sum( lst )
dic2 [ i ] = sum_of_num

print(dic2)
Username and pass
dic = {'Path' : "2003",
'walla' : "1809",
'Portal' : "1912",
'Express' : "2003",
'Computer' : "9834",
'Python' : "1990",
'Mysql' : "2001",
'c++' : "1996",
'java' : "1998",
'html' : "1999" }

username = input("Enter username :- ")

if username in dic :
password = input("Enter password :- ")
if dic[username] == password :
print ("You are now logged into the system.")
else :
print ("Invalid password.")
else :
print ("You are not valid user.")

You might also like