# important class 11 python dictionary program accepts transaction details and displays balance

In this article, we are going to discuss a class 11 python dictionary program that accepts transaction details in dictionary form and displays the balance accordingly. Let us begin!

Topics Covered

## Class 11 Python Dictionary Program – Bank transaction and update balance

The complete definition of a program is as follows:

Write a program to accept transaction details in dictionary form and display updated balance.

Let us begin the process for the program.

### Variables Required for Input and Output

So as per the questions given, we need the following variables:

1. Balance
2. A dictionary accepts the transaction details where transaction type (D for Debit and C for Credit) as a key and amount as a value
3. i for traversing a dictionary in for loop

### Steps

1. Declare a variable for initial balance. In our program its bal = 50000
2. Print the initial balance
3. Prompt for transaction detail using eval(inut())
4. Take a for loop to traverse a dictionary
5. Now apply if condition for the appropriate function as per the transaction
6. Check the key, if it is ‘D’ deduct value from bal
7. If the key is ‘C’ add the value into bal
8. Print the updated closing balance

### Code

Observe the code for the program:

``````'''Write a program to accept transaction details
in dictionary form and display balance.'''
#For example:
#Enter transaction:{'D':5000}
#Output should be:
'''Initial Balance - 50000
Closing Balance after transaction - 45000'''

#Step 1 Initiate Balance
bal=50000

#Input transaction details
tr=eval(input("Enter transaction detail:"))

#Printing Initial Balance
print("Initial Balance - ",bal)

#Traversing Dictionary to perform the transaction
for i in tr:
#Checking if transaction for debit and update balance
if i=='D':
#Update balance
bal-=tr[i]
#Checking if transaction for credit and update balance
if i=='C':
bal+=tr[i]

#Printing closing balance
print("Closing Balance After transaction - ",bal)
``````

### Output

Watch this video for practical demo:

I hope this program helps you to understand the concept dictionary and how to work with a dictionary in python. If you have any doubts or queries or want to share your views about our website you are welcome to share.

Your views/suggestions/feedbacks related to this article class 11 python dictionary program are also welcome. Feel free to share in the comment section.