Format variables using a string.format() method.
Write a python program to use string.format() method to format the following three variables as per the expected output
Write a python program to use string.format() method to format the following three variables as per the expected output
totalMoney = 1000 quantity = 3 price = 450
I have 1000 dollars so I can buy 3 football for 450.00 dollars.
quantity = 3
totalMoney = 1000
price = 450
statement1 = "I have {1} dollars so I can buy {0} football for {2:.2f} dollars."
print(statement1.format(quantity, totalMoney, price))
I have 1000 dollars so I can buy 3 football for 450.00 dollars.
First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.