---
title: "How to Spell out Number Using Dictionary in Python"
description: "Here is a sample python program to spell out a number using dictionary data type. And it is helpful for interviews and project purposes."
url: https://srinimf.com/2021/12/04/python-program-to-spell-out-number/
date: 2021-12-04
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2021/12/pexels-photo-4144923.jpeg?fit=1880%2C1255&ssl=1
categories: ["Python"]
tags: ["How to spell out number", "python programs"]
type: post
lang: en
---

# How to Spell out Number Using Dictionary in Python

Here is a Python program that *spells out a number* using a dictionary.

Related[3 Ways to Convert Python Dictionary into JSON Format](https://srinimf.com/2023/07/10/python-methods-to-format-dictionary-to-json-quickly/)

How it works is – if you enter numeric ‘1’, it displays ‘one’ as a character.

*Python supports three types of compound data types. *

*Those are List, Tuple, and Dictionary.*Out of these, I used a dictionary-type to achieve this.

## [What is](https://srinimf.com/2022/10/03/what-is-multitasking-in-python-and-how-it-supports/) [python dictionary](https://srinimf.com/2023/09/29/how-to-merge-python-dictionaries-3-methods/)?

You can create an empty dictionary with empty curling braces. It supports data of type **key/value **pairs.

```
my_dictionary = {}
```

Here is a dictionary with data of two key-value pairs.

```
my_dictionary = {"name" : "Srini", "age" : 20}
```

Further to, you can get data from a dictionary by giving the key value.

```
my_dictionary["name"] ==> it will display Srini
```

## Here is screen shot of the results

As said, with the key, you can print its value. The same concept I used [to write](https://srinimf.com/2012/03/12/cobol-release-and-return-in-sort/) the program.

![How to display dictionary data using key](https://i0.wp.com/srinimf.com/wp-content/uploads/2021/12/dictionary.png?resize=995%2C590&ssl=1)

## Here is python logic to spell out a number

```
#!/usr/bin/python3
## This program spells out the number
my_input = input("Enter number from 1 to 4: ")
my_dict_mapping = {
    
    "1" : "One",
    "2" : "Two",
    "3" : "Three",
    "4" : "Four"
}
for i in my_dict_mapping:
    if i == my_input:   
        print (my_dict_mapping[i])
        break
    else:
        print ("Mind your entry!!")
```

Related[Here is Logic to Write UDF to Check Input is Number or not](https://srinimf.com/2021/12/06/function-that-checks-input-value-is-number-or-not/)

### The output after you execute the program

![Python program how to use dictionary](https://i0.wp.com/srinimf.com/wp-content/uploads/2021/12/result-of-python-spell-out.png?resize=1061%2C815&ssl=1)

So, the output is **one** for the input ‘1’ that you entered.

You can try the same program in your python interpreter too.

If the input value does not match the dictionary key-value, it will display as “Mind your entry!!”

Related posts

- [3 Ways to Convert Python Dictionary into JSON Format](https://srinimf.com/2023/07/10/python-methods-to-format-dictionary-to-json-quickly/)DateJuly 10, 2023
- [Efficient Python Dictionary Merge: update(), ** Operator, dict() Constructor](https://srinimf.com/2023/09/29/how-to-merge-python-dictionaries-3-methods/)DateSeptember 29, 2023
- [How to Create a JSON File in Python: Step-by-Step Guide for Beginners](https://srinimf.com/2021/11/12/how-to-create-json-file-in-python/)DateNovember 12, 2021

Get new content delivered directly to your inbox.

Type your email…

Sign up

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2021%2F12%2F04%2Fpython-program-to-spell-out-number%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2021%2F12%2Fpexels-photo-4144923.jpeg%3Ffit%3D1200%252C801%26ssl%3D1&description=How%20to%20Spell%20out%20Number%20Using%20Dictionary%20in%20Python)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2021/12/04/python-program-to-spell-out-number/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2021/12/04/python-program-to-spell-out-number/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2021/12/04/python-program-to-spell-out-number/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2021/12/04/python-program-to-spell-out-number/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20How%20to%20Spell%20out%20Number%20Using%20Dictionary%20in%20Python&body=https%3A%2F%2Fsrinimf.com%2F2021%2F12%2F04%2Fpython-program-to-spell-out-number%2F&share=email)
-

### Like this:

Like Loading…