Uploaded by jemox73304

dictionary

advertisement
Code :
while True:
print("********************** Dictionary Methods **********************")
print("1. Empyty dictionary with user input")
print("2. Using dict function")
print("3. Using curly Braces")
print("4. Using zip function")
print("5. Exit")
print("***********************************************************************")
ch = input("Enter your choice : ")
if ch == '1':
dict1 = {}
n = int(input("Enter a number : "))
# dictionart with user input
for i in range(n):
key = int(input(f"Enter key {i + 1} : "))
value = input("Enter Value : ")
dict1[key] = value
print(dict1)
elif ch == '2':
dict3 = dict({2141001: 'Adarsha', 2141002: 'Aditya', 2141011: 'Bijosh'})
print(dict3)
elif ch == '3':
dict2 = {2141019: 'Krish', 2141014: 'Harpreet', 2141015: 'Harsh'}
print(dict2)
elif ch == '4':
keys = [532215,532210,500010]
values = ['Axix Bank', 'Citi Union Bank', 'HDFC Bank']
dict4 = dict(zip(keys, values))
print(dict4)
elif ch == '5':
print("************************ Thank you ************************")
break
else:
print("Invalid choice. Please try again.")
print()
Output :
/Users/harpreetkamboj/PycharmProjects/pythonProject1/venv/bin/python /
Users/harpreetkamboj/PycharmProjects/pythonProject1/dictionary.py
********************** Dictionary Methods **********************
1. Empyty dictionary with user input
2. Using dict function
3. Using curly Braces
4. Using zip function
5. Exit
***********************************************************************
Enter your choice : 1
Enter a number : 2
Enter key 1 : 11
Enter Value : aa
Enter key 2 : 22
Enter Value : bb
{11: 'aa', 22: 'bb'}
********************** Dictionary Methods **********************
1. Empyty dictionary with user input
2. Using dict function
3. Using curly Braces
4. Using zip function
5. Exit
***********************************************************************
Enter your choice : 2
{2141001: 'Adarsha', 2141002: 'Aditya', 2141011: 'Bijosh'}
********************** Dictionary Methods **********************
1. Empyty dictionary with user input
2. Using dict function
3. Using curly Braces
4. Using zip function
5. Exit
***********************************************************************
Enter your choice : 3
{2141019: 'Krish', 2141014: 'Harpreet', 2141015: 'Harsh'}
********************** Dictionary Methods **********************
1. Empyty dictionary with user input
2. Using dict function
3. Using curly Braces
4. Using zip function
5. Exit
***********************************************************************
Enter your choice : 4
{532215: 'Axix Bank', 532210: 'Citi Union Bank', 500010: 'HDFC Bank'}
********************** Dictionary Methods **********************
1. Empyty dictionary with user input
2. Using dict function
3. Using curly Braces
4. Using zip function
5. Exit
***********************************************************************
Enter your choice : 5
************************ Thank you ************************
Process finished with exit code 0
Download