Programming Examples
Python program to create a dictionary has three keys assets liabilities and capital
A dictionary has three keys: 'assets', 'liabilities' and 'capital'. Each of these keys store their value in form of a list storing various values of 'assets', liabilities' and 'capital' respectively. Write a program to create a dictionary in this form and print. Also test if the accounting equation holds true.
Solution
assets = eval(input("Enter assets list : "))
liability = eval(input("Enter liability list : "))
capital = eval(input("Enter capital list : "))
dic = { "assets" : assets , "liability" : liability , "capital" : capital }
print("Result Dictionary is :",dic)
total_assets=0
total_liability=0
total_capital=0
for i in range( len( dic[ "assets" ] ) ) :
total_assets=total_assets+dic [ "assets" ][ i ]
for i in range( len( dic[ "liability" ] ) ) :
total_liability=total_liability+dic [ "liability" ][ i ]
for i in range( len( dic[ "capital" ] ) ) :
total_capital=total_capital+dic [ "capital" ][ i ]
if total_assets == total_liability+ total_capital:
print("Balanced")
else:
print("Not Balanced")
Output/ Explanation:
Enter assets list : [3000,5000,2000]
Enter liability list : [4000,1500,2000]
Enter capital list : [500,2000]
Result Dictionary is : {'assets': [3000, 5000, 2000], 'liability ': [4000, 1500, 2000], 'capital': [500, 2000]}
Balanced
------------------------------------------------------------------------------------------
Enter assets list : [3000,4000,4000]
Enter liability list : [5000,9000]
Enter capital list : [3000,5000]
Result Dictionary is : {'assets': [3000, 4000, 4000], 'liability': [5000, 9000], 'capital': [3000, 5000]}
Not Balanced