Write a Python code to create a dictionary containing four products with their names as keys and
their sales as values, respectively. Display the dictionary with the names of the products and also the
product having the highest sale.
name=input("Enter your name :")
dict={'Apple':65,'Brinjal':82,'Banana':75}
for x in dict:
print(x,':',dict[x])
high_item= max(dict)
print("Highest product is",high_item)
Write a Python code to assign three dictionaries, each containing the name, age, and salary of an
employee. The company has decided to increase the salary by 20% for the employees whose age is 55
years and above. Display the original and updated dictionaries.
empl3 = {'name': 'Alice', 'age': 56, 'salary': 50000}
empl2 = {'name': 'Bob', 'age': 45, 'salary': 60000}
empl1 = {'name': 'Charlie', 'age': 55, 'salary': 70000}
empl=[empl1,empl2,empl3]
print(empl)
for emp in empl:
if emp['age']>=55:
emp['salary']*=1.2
for emp in empl:
print(emp)
Write a Python code to assign two dictionaries, one containing states' names as values and the other
containing the corresponding capitals' names. Now, enter a state name and search for it in the
dictionary of states' names. If found, then display the state name along with its capital name,
otherwise, display "State name not found."
states = {'Gujarat': 'Gandhinagar','Maharashtra': 'Mumbai','Rajasthan': 'Jaipur','Karnataka':
'Bengaluru','Tamil Nadu': 'Chennai'}
sn=input("Enter the state name:")
if sn in states:
print("The state is",sn,"it's capital is",states[sn])
else:
print("State not found")
Write a Python code to input a string and find the frequencies of each character of the string. Finally,
it returns as a dictionary with the key as the character and its value as its frequency in the given
string.
str=input("Enter the stringL:")
l=list(str)
freq=[l.count(ele) for ele in l]
d=dict(zip(l,freq))
print(d)
Write a Python code to create a dictionary containing English words corresponding to their suitable
keys. Display such words which start and end with the same letter. Also, display the frequency of all
such words.
words_dict = {'apple': 1,'banana': 2,'level': 3,'madam': 4,'racecar': 5,'civic': 6,'hello': 7,'radar': 8}
same_letterwords={}
for word,freq in words_dict.items():
if word[0] == word[-1]:
same_letterwords[word] = freq
print(same_letterwords)
for x in same_letterwords:
print(x,':',same_letterwords[x])
Write a Python code to assign a dictionary containing letters of the English alphabet as values along
with suitable keys. Find and display the number of vowels and consonants.
# Create a dictionary with letters of the English alphabet
alphabet_dict = {1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e', 6: 'f', 7: 'g', 8: 'h',
9: 'i', 10: 'j', 11: 'k', 12: 'l', 13: 'm', 14: 'n', 15: 'o',
16: 'p', 17: 'q', 18: 'r', 19: 's', 20: 't', 21: 'u', 22: 'v',
23: 'w', 24: 'x', 25: 'y', 26: 'z'}
# Vowel list
vowels = ['a', 'e', 'i', 'o', 'u']
# Counters
vowel_count = 0
consonant_count = 0
# Loop to count vowels and consonants
for letter in alphabet_dict.values():
if letter in vowels:
vowel_count += 1
else:
consonant_count += 1
# Display the counts
print("Number of vowels:", vowel_count)
print("Number of consonants:", consonant_count)