100% found this document useful (1 vote)
1K views90 pages

Dictionary 2024 2025

Uploaded by

jackdaripper351
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
100% found this document useful (1 vote)
1K views90 pages

Dictionary 2024 2025

Uploaded by

jackdaripper351
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/ 90

DICTIONARY

Dictionary

Definition:
It is an unordered collection of
items where each item consist of a key
and a value.

It is mutable (can modify its contents ) but


Key must be unique and immutable.
INTRODUCTION

• The data type dictionary fall under mapping.


• It is a mapping between a set of keys and a set
of values.
• The key-value pair is called an item.
Features of Dictionary In Python
• Dictionary in Python holds data items in key-value
pairs.
• Items in a dictionary are enclosed in curly brackets
{ }.
• Every key is separated from its value using a colon
(:) sign.
• The key : value pairs of a dictionary can be accessed
using the key.
• In order to access any value in the dictionary, we
have to specify its key in square brackets [ ]
Creating a Dictionary
#dict1 is an empty Dictionary created
#curly braces are used for dictionary
Syntax:
Dict1={K1:V1,K2:V2,K3:V3}
>>> dict1 = {}
>>> dict1 {}
#dict2 is an empty dictionary created using built-in function
>>> dict2 = dict()
>>> dict2 {}
#dict3 is the dictionary that maps names of the students to
respective marks in percentage
>>> dict3 = {'Mohan':95,'Ram':89,'Suhel':92, 'Sangeeta':85}
>>> dict3
{'Mohan': 95, 'Ram': 89, 'Suhel': 92, 'Sangeeta': 85}
Accessing Items in a Dictionary
Accessing Items in a Dictionary
We have already seen that the items
of a sequence (string, list and tuple)
are accessed using a technique called
indexing.
The items of a dictionary are accessed
via the keys rather than via their
relative positions or indices. Each key
serves as the index and maps to a
value.
The following example shows how a dictionary returns the
value corresponding to the given key:
>>>dict3={'Mohan':95,'Ram':89,’Kumar':92, 'Sangeeta':85}
>>> dict3['Ram']
89
>>> dict3['Sangeeta']
85
#the key does not exist
>>> dict3['Shyam']
KeyError: 'Shyam'
In the above examples the key 'Ram' always maps to the
value 89 and key 'Sangeeta' always maps to the value 85.
So the order of items does not matter. If the key is not
present in the dictionary we get KeyError.
Dictionaries are Mutable
Dictionaries are mutable which implies that the contents of the
dictionary can be changed after it has been created.
1.Adding a new item
We can add a new item to the dictionary as shown in the following
example:
>>> dict1 = {'Mohan':95,'Ram':89,’kumar':92, 'Sangeeta':85}
>>> dict1['Meena'] = 78
>>> dict1
{'Mohan': 95, 'Ram': 89, 'kumar': 92, 'Sangeeta': 85, 'Meena': 78}
2 Modifying an Existing Item
The existing dictionary can be modified by just overwriting the key-
value pair. Example to modify a given item in the dictionary:
>>> dict1 = {'Mohan':95,'Ram':89,'kumar':92, 'Sangeeta':85}
#Marks of Suhel changed to 93.5
>>> dict1['kumar'] = 93.5
>>> dict1 {'Mohan': 95, 'Ram': 89, 'kumar': 93.5, 'Sangeeta': 85}
RECAP OF LAST CLASS
TOPIC
TODAY’S TOPIC

1.Dictionary Operation

2.Traversing in a Dictionary
1.Dictionary Operation
Dictionary Operation
There is only one operator available in Python Dictionary
that is Membership Operator.
The membership operator checks if the key is present in the
dictionary or not if present it returns True, else it returns
False.
>>> dict1 = {'Mohan':95,'Ram':89,'Sai':92, 'Sangeeta':85}
>>> ‘Sai' in dict1
True
The not in operator returns True if the key is not present in
the dictionary, else it returns False.
>>> dict1 = {'Mohan':95,'Ram':89,'Sai':92, 'Sangeeta':85}
>>> 'Sai' not in dict1
False
2.Traversing in a Dictionary
Traversing a Dictionary
We can access each item of the dictionary or
traverse a dictionary using for loop.
Given Dictionary:
dict1={'Mohan':90,'Glen':89,'Sri Ram':92, 'Sangeetha':85}
Method 1
for i in dict1:
print(i,':',dict1[i])
output
Mohan : 90
Glen : 89
Sri Ram : 92
Sangeetha : 85
Method 2 :
dict1={'Mohan':90,'Glen':89,'Sri Ram':92, 'Sangeetha':85}
for k, v in dict1.items():
print(k,':’,v)

Output
Mohan : 90
Glen : 89
Sri Ram : 92
Sangeetha : 85
CLASSROOM ACTIVITY

Write a program to create a Phone


dictionary for storing all your friends Phone
numbers and print them by using Dictionary
concept.
Write a program to create a Phone dictionary
for storing all your friends Phone numbers and
print them by using Dictionary concept.

Sample Input

66555454:”Gouri",45654633:”shaji",45645645:”M
anav",56456456:"Juan“,55445655:"Glen"}
CODING
Phone_dict={66555454:”Gouri",4565463:”shaji",4564564
5:”Manav",56456456:"Juan“,45655:"Glen"}

for i in Phone_dict:
print(i,':',Phone_dict[i])
FLIP LEARNING TASK
CODING BY DYNAMIC INPUT
How many Friend's Phone number to be Stored :3
Enter the Phone Number of your friend:33335343
Enter the Name of your friend:Gouri
Enter the Phone Number of your friend:35343433
Enter the Name of your friend:Glen
Enter the Phone Number of your friend:33336666
Enter the Name of your friend:Abinav
MY Friend Phone Details
33335343 : Gouri
35343433 : Glen
33336666 : Abinav
CODING BY DYNAMIC INPUT

Total=int(input("How many Friend's Phone number to be Stored :"))


Phone_dict={}
for a in range(Total):
Key=int(input("Enter the Phone Number of your friend:"))
Value=input("Enter the Name of your friend:")
Phone_dict[Key]=Value
print("MY Friend Phone Details")
for i in Phone_dict:
print(i,':',Phone_dict[i])
RECAP OF TODAY’S TOPIC
Tomorrow's Lab Exercise

41.Write a program to count the number of times


a character appears in a given string by using
dictionary.

42.Program to create a dictionary which stores


names of the employee and their salary by using
Dictionary Concept
NEXT TOPIC
Built- in Functions & Methods Python in Dictionary
1.Write a program to count the number of times a
character appears in a given string by using dictionary

st = input("Enter a string: ")


dic = {} #creates an empty dictionary
for ch in st:
if ch in dic: # if next character is already in the dictionary
dic[ch] += 1
else:
dic[ch] = 1 #if ch appears for the first time
for key in dic:
print(key,':',dic[key])
output

Enter a string: welcome


w:1
e:2
l:1
c:1
o:1
m:1
HW
Program to create a dictionary which
stores names of the employee and their
salary by using Dictionary
#Program to create a dictionary which stores names of the employee
#and their salary

num = int(input("Enter the number of employees whose data to be


stored: "))
count = 1
employee = dict() #create an empty dictionary
while count <= num:
name = input("Enter the name of the Employee: ")
salary = int(input("Enter the salary: "))
employee[name] = salary
count += 1
print("\n\nEMPLOYEE_NAME\tSALARY")
for k in employee:
print(k,'\t\t',employee[k]) #print('\t\t',employee[k])
OUTPUT
Enter the number of employees whose data to be stored: 3
Enter the name of the Employee: edward
Enter the salary: 600
Enter the name of the Employee: sai
Enter the salary: 800
Enter the name of the Employee: Andrew
Enter the salary: 400

EMPLOYEE_NAME SALARY
edward 600
sai 800
Andrew 400
LAB PRACTICAL

The dictionary, S contains Name:[Eng,Math,Science] as key:value pairs. Displays the


corresponding grade obtained by the students according to the following grading rules :

For example : Consider the following dictionary


S={"AMIT":[92,86,64],"NAGMA":[65,42,43],"DAVID":[92,90,88]}
The output should be :
AMIT – B
NAGMA – C
DAVID – A
S={"AMIT":[92,86,64],"NAGMA":[65,42,43],"DAVID":[92,90,88]}

for K in S:
Sum=0
for i in range(3):
Sum+=S[K][i]
if Sum/3>=90:
Grade="A"
elif Sum/3>=60:
Grade="B"
else:
Grade="C"
print(K,"–",Grade)
Built- in Functions & Methods in Dictionary
TODAY’S TOPIC

Built- in Functions & Methods in Dictionary


len(),
dict(),
keys(), Functions & Methods in Dictionary

values(),
items(),
get(),
update(),
Built- Functions in Dictionary
Function & Description

len(dict1)Gives the total length of the dictionary. It is equal to


the number of items in the dictionary.
dict1 = {'Name': 'Aman', 'Age': 37}
print ("Length : " , len (dict))
OUTPUT ->
Length : 2
type(variable)If variable is dictionary, then it would return a
dictionary type.
>>> dict1 = {'Name': 'Aman', 'Age': 37}
>>> type(dict1)
<class 'dict'>
Method & Description

dict() - Creates a dictionary from a sequence of key-value pairs


>>> x = dict(name = "Aman", age = 37, country = "India")
>>> x
{'name': 'Aman', 'age': 37, 'country': 'India'}
Here x is created as dictionary

keys() - returns all the available keys


d1={"name":"Aman","age":37,"country":"India"}
print(d1.keys())
OUTPUT->
dict_keys(['name', 'age', 'country', ])
Takes No arguments, returns a list sequence of keys

values() - returns all the available values


>>> d1={"name":"Aman","age":37,"country":"India"}
>>> d1.values()
OUTPUT->
dict_values(['Aman', 37, 'India’])
Takes No arguments, returns a list sequence of values
Built-in Methods in Dictionary

Method & Description


items() - return the list with all dictionary keys with values. It Returns a list of tuples(key
– value) pair.
d2={'name': 'Aman', 'age': 37, 'country': 'India’}
print(d2.items())
OUTPUT->
dict_items([('name', 'Aman'), ('age', 37), ('country', 'India’)])
Takes No arguments, returns a list sequence of (Key, values) pairs
get()- Display the value of the given key-only one argument (Key)
dict1={‘Name ‘: "Aman", ‘age’ =:17, ‘country ‘:"India")

>>> dict1.get('Name')

'Aman’

If the Key is not present in the dictionary, Python by default gives


error or None, but you can specify your own message through
argument as per the following syntax:

<dictionary>.get(key,[default value])
Example
Emp2={"Name":"Gouri","Salary": 3000,"Dep":"IT"}
print(Emp2.get("Age","Error!!!!The given Key is not
found"))
update()-
This method merges key : value pair from the new
dictionary into the original dictionary, adding or
replacing as needed. The items in the new
dictionary are added to the old one and override
any items already there with the same keys.
Example:
The given Dictionary:
Emp1 = {'Name': 'Glen', 'Salary': 2000, 'Age': 16}
Emp2 = {'Name': 'Gouri', 'Salary': 3000, 'Dep': 'IT’}
Emp1.update(Emp2)
Print(Emp1) print(Emp2)
After Updating Emp1 and Emp2:
Emp1 : {'Name': 'Gouri', 'Salary': 3000, 'Age': 16, 'Dep': 'IT'}
Emp2 : {'Name': 'Gouri', 'Salary': 3000, 'Dep': 'IT'}
CLASSROOM ACTIVITY
Create a dictionary of odd numbers between 1 and
10, where the key is the decimal number and the
value is the corresponding number in words.
Example:
ODD = {1:'One',3:'Three',5:'Five',7:'Seven',9:'Nine'}
Perform the following operations on this dictionary:
(a) Display the all the keys present in the dictionary
(b) Display the all the values present in the dictionary
(c) Display the items present in the dictionary
(d) Find the length of the dictionary
(e) Check if 7 is present or not
(f) Check if 2 is present or not
(g) Retrieve the value corresponding to the key 9
>>> ODD = {1:'One',3:'Three',5:'Five',7:'Seven',9:'Nine'}
>>> ODD
{1: 'One', 3: 'Three', 5: 'Five', 7: 'Seven', 9: 'Nine'}
(a) Display the keys
>>> ODD.keys()
dict_keys([1, 3, 5, 7, 9])
(b) Display the values
>>> ODD.values()
dict_values(['One', 'Three', 'Five', 'Seven', 'Nine'])
(c) Display the items
>>> ODD.items()
dict_items([(1, 'One'), (3, 'Three'), (5, 'Five'), (7, 'Seven'), (9,
'Nine')])
(d) Find the length of the dictionary
>>> len(ODD)
5
(e)Check if 7 is present or not
>>> 7 in ODD ----True
(f) Check if 2 is present or not
>>> 2 in ODD ----False
(g) Retrieve the value corresponding to the key 9
>>> ODD.get(9)-- 'Nine'
RECAP OF TODAY’S TOPIC
Home Work

1.Create dictionary to store n number of student details


with rollno, name, age and Search a particular student
details from dictionary items and print that details.

2. Create dictionary for month and no of days for a


year. User is asked to enter month name and system
will show no of days of that month.
NEXT TOPIC
Built- in Functions & Methods Python in Dictionary
Continue

del(), clear(),
fromkeys(), copy(),
pop(), popitem(),
setdefault(),
RECAP OF LAST CLASS
TOPIC
TODAY’S TOPIC
Built- in Functions & Methods Python in Dictionary
Continue

setdefault(),
del(), clear(), pop(),
fromkeys()
setdefault() method

This method insert a new Key : value if the key


does not exist. If the key already exist ,it return
the current value of the key.
Dict.setdefault(key,value)
if the value is not passed as input, the default
None value is used as the value.
EXAMPLE

Marks={1:350,2:400,3:450}
Marks.setdefault(4,350)
print(Marks)
Marks.setdefault(3,350)
print(Marks)
Marks.setdefault(6)
print(Marks)
{1: 350, 2: 400, 3: 450, 4: 350}
{1: 350, 2: 400, 3: 450, 4: 350}
{1: 350, 2: 400, 3: 450, 4: 350, 6: None}
Dictionary
Deleting Dictionary Items
del, pop() and clear() statement are used to remove
items from the dictionary.
del ()-used to remove key

Example for del:

dict1 = {'Subject': 'Computer Science', 'Class': 11}


print('before del', dict)

del dict1['Class'] # delete single


element
print('after item delete', dict)

del dict1 #delete whole


dictionary
Output

('before del', {'Subject': 'Computer Science' ,'Class':


11, })
('after item delete', {'Subject': 'Computer Science '})
('after dictionary delete', <type 'dict'>)
Dictionary
pop() method is used to remove a particular item in a
dictionary.
clear() method is used to remove all items from
the dictionary.
e.g.
dict = {'Subject': 'Computer Science ',
'Class': 11}
print('before del', dict)
dict.pop('Class')
print('after item delete', dict)
dict.clear()
print('after clear', dict)
Output
before del
{'Subject': 'Computer Science', 'Class': 11}
after item delete
{'Subject': ’Computer Science'}
after clear
{}
Difference between pop and del
The only difference between two is that-
pop return the value of the key which was removed
and del does not return anything.
Pop is only way that returns the object.
>>> d1={1:"One",2:"two",3:"Three"}
>>> del(d1[2])
>>> d1
{1: 'One', 3: 'Three'}
>>> d1.pop(3) # pop doesn't only delete, it also returns, what it deletes
from the Key
'Three'
>>> d1
{1: 'One'}
Write a Program to create a dictionary
which stores names of student and roll
number after that remove one item from
the dictionary by using roll number.
Stud_Dict={1001:“Manav",1002:"Shaji",1003:"Sam",1004:“
Gouri",1005:“Aman"}
#print(Stud_Dict)
print("Enter the RegNo to be Removed (Key)")
remove_roll=int(input())
print("The given Roll number (key) to remove is =
",remove_roll)
for i in Stud_Dict:
if i==remove_roll:
remove_Item=Stud_Dict.pop(i)
print("The Removed Values = ",remove_Item)
break
TODAY’S TOPIC
Built- in Functions & Methods Python in Dictionary
Continue

popitem(), fromkeys(),copy()
popitem() – removes last item from dictionary
and return the removed dictionary item.
x={'name':'Aman','age':37,'country':'India'}
n=x.popitem()
print(n)
print(type(n))
print(x)

OUTPUT->
('country', 'India')
<class 'tuple'>
{'name': 'Aman', 'age': 37}
Note : popitem() takes no arguments
Built-in Methods in Dictionary
Method & Description

fromkeys()
1. It is used to create new dictionary from a sequence
containing all the keys and a common value, which
will be assigned to all the keys.
keys = {'a', 'e', 'i', 'o', 'u' }
value ="Vowel"
vowels=dict.fromkeys(keys,
value)
print(vowels)
OUTPUT->
{'i': 'Vowel', 'u': 'Vowel', 'e': 'Vowel', 'a': 'Vowel', 'o':
'Vowel'}
fromkeys()
2.If you only specify the key sequence and do not give any value , it
will take None as the values for the keys

>>>Newdict=dict.fromkey((3,4,5))
>>> print(Newdict)
{3: None, 4: None, 5: None}

3.If you specify the sequence of values in place of the value


argument, it will consider the whole sequence as the value for the
keys
>>> Newdict=dict.fromkeys((3,4,5),(6,7,8))
>>> print(Newdict)
{3: (6, 7, 8), 4: (6, 7, 8), 5: (6, 7, 8)}
4.The Keys argument must be an iterable sequence, even if you have a
single key. The keys argument should be in Tuple format or list format.

D1=dict.fromkeys(3) #TypeError:'int' object is not iterable


D2=dict.fromkeys(3,) #TypeError: 'int’ object is not iterable

Example: Correct Method

>>> D1=dict.fromkeys((3,))
>>> D1
{3: None}

>>> D2=dict.fromkeys([3])
>>> D2
{3: None}
CLASSROOM ACTIVITY

Your School has decided to deposit scholarship


amount Rs.2500 to some selected student. Write a
program to input the selected students roll
number and create a dictionary for the same.
L=[]
N=int(input("Enter How Many Students:"))
for a in range(N):
r=int(input("Enter Roll number:"))
L.append(r)
Scholarship =dict.fromkeys(L,2500)
print("Created Scholarship Dictionary")
print(Scholarship )
Method & Description

copy() - returns a shallow copy of the dictionary.


x = {'name': 'Aman', 'age': 37, 'country’:
'India’}
y=x.copy()
print(y)
print(id(x))
print(id(y))
OUTPUT - >
{'name': 'Aman‘, 'age': 37, 'country': 'India',}
33047872
33047440
1. If the Values are referred by the keys are immutable

x ={'Name':'Aman','age':37,'country':'India'}
print(x)
y=x.copy()
print(y)
print(id(x))
print(id(y))
y["Mobile"]=33333
print("After adding New item in Y")
print(x)
print(y)
print(id(x))
print(id(y))
OUTPUT

{'Name': 'Aman', 'age': 37, 'country': 'India'}


{'Name': 'Aman', 'age': 37, 'country': 'India'}
52966016
55316840
After adding New item in Y
{'Name': 'Aman', 'age': 37, 'country': 'India'}
{'Name': 'Aman', 'age': 37, 'country': 'India', 'Mobile': 33333}
52966016
55316840
2. If the Values are referred by the keys are Mutable(List)
d1={1:[1,2,3],2:[3,4,5]}
d2=d1.copy()
d2[1].append(4)
print(d1)
print(d2)
print(id(d1))
print(id(d2))
OUTPUT
{1: [1, 2, 3, 4], 2: [3, 4, 5]}
{1: [1, 2, 3, 4], 2: [3, 4, 5]}
52965696
52981800
RECAP OF TODAY’S TOPIC
TODAY’S TOPIC
Built- in Methods Python in Dictionary
Continue

max() min(), sum()


max(),min(),and sum()

These functions work with the keys of dictionary and thus


for these functions to work the dictionary keys must be of
homogenous type.

Example:
#1. Dictionary having homogeneous keys (all of tuple type)
d1={(1,2):"One",(3,4):"Two"}
print(d1)

# 2.Dictionary having homogeneous keys (all of str type)


d2={"Name":"Sekar","Address":"Manama"}
print(d2)
Example:

# 3.Dictionary having homogeneous keys (all of int type)


d3={40:"Fourty", 50:"Fifty"}
print(d3)

# 4.Dictionary having homogeneous keys (all of float


type)
d4={1.2:"A", 3.4:"B"}
print(d4)
max(),min()

Example:
d1={(1,2):"One",(3,4):"Two"}
d2={"Name":"Sekar","Address":"Manama"}
d3={40:"Fourty", 50:"Fifty"}
d4={1.2:"A", 3.4:"B"}
print(min(d1),min(d2),min(d3),min(d4))
print(max(d1),max(d2),max(d3),max(d4))

Output
min and Max
(1, 2) ,Address, 40, 1.2
(3, 4) ,Name ,50, 3.4
sum()
Example:
d1={(1,2):"One",(3,4):"Two"}
d2={"Name":"Sekar","Address":"Manama"}
d3={40:"Fourty", 50:"Fifty"}
d4={1.2:"A", 3.4:"B"}
Out of the above given dictionary only two dictionaries d3 and d4 have the keys
which ca be added(int and float type)
The keys of dictionaries d1 and d2 are not addition compatible as the tuple and
string can not be added.
print(sum(d3))
print(sum(d4))
print(sum(d1))
print(sum(d2))
Output:
90
4.6
TypeError: unsupported operand type(s) for +: 'int' and 'tuple'
TypeError: unsupported operand type(s) for +: 'int' and 'str'
Note:
max(),min(),and sum() will only work with:

1. Dictionaries having homogenous keys that can be compared


2. The sum() method can only work with dictionaries having keys
which are addition compatible.
CLASSROOM ACTIVITY

Write a program to print the max(),min(),and


sum() of keys of number dictionary as given
bellow:
number={1:200,2:300,3:350,4:400}
NEXT TOPIC
Built- in Functions & Methods Python in Dictionary
Continue

sorted()
sorted() function

sorted() function consider only the keys of the dictionary for


sorting and returns a sorted list of the dictionary keys.

The sorted() function will return the sorted result always in the list
form.
.

Syntax:

sorted(<dict>,[reverse=False])
D1={1002:"Johan",1001:"Gouri",1004:"Ram",1003:"Annu"}

#Sorting By Default

print(D1)
D2=sorted(D1)
print(D2)
[1001, 1002, 1003, 1004]

#Sorting By Descending Order


D3=sorted(D1,reverse=True)
print(D3)
[1004, 1003, 1002, 1001]
D1={1002:"Johan",1001:"Gouri",1004:"Ram",1003:"Annu"}
#Sorting By keys
D3=sorted(D1.keys())
print(D3)
[1001, 1002, 1003, 1004]
#Sorting By Values
D4=sorted(D1.values())
print(D4)
['Annu', 'Gouri', 'Johan', 'Ram']
#Sorting By items
D5=sorted(D1.items())
print(D5)
[(1001, 'Gouri'), (1002, 'Johan'), (1003, 'Annu'), (1004, 'Ram')]
Important
For the sorted() function to work, all the keys should be homogeneous.

D1={(3,4):"Two",(1,2):"One"}
D2=sorted(D1)
print(D2)
[(1, 2), (3, 4)]

D3={"Johan":"Manama","Gouri":"Riffa","Ram":"Sanad","Annu":"Manama"}
D4=sorted(D3)
print(D4)
['Annu', 'Gouri', 'Johan', 'Ram']

D8={1002:"Johan",1001:"Gouri",1004:"Ram","1003":"Annu"}
D9=sorted(D8)
print(D9)
TypeError: '<' not supported between instances of 'str' and 'int'
len(), dict(), keys(), values(), items(), get(), update(),
del(), clear(), fromkeys(), copy(), pop(), popitem(),
setdefault(), max(), min(), count(), sorted(), copy();
CLASSROOM
44.Write a program ACTIVITY
to input your friends’ names and their
Phone Numbers and store them in the dictionary as the key-
value pair. Perform the following operations on the
dictionary:
a) Display the name and phone number of all your friends.
b) Add a new key-value pair in this dictionary and display
the modified dictionary
c) Delete a particular friend from the dictionary .
d) Modify the phone number of an existing friend.
e) Check if a friend is present in the dictionary or not
f) Display the dictionary in sorted order of names
Home Work

1.Create dictionary to store n number of student details


with rollno, name, age and Search a particular student
details from dictionary items and print that details.

45. Create dictionary for month and no of days for a


year. User is asked to enter month name and system
will show no of days of that month.

3. Write a function to convert a number entered by the


user into its corresponding number in words. For
example, if the input is 876 then the output should be
‘Eight Seven Six’.

You might also like