Format variables using a string.format() method.

Python / Fundamentals of Python

408

Given Input:

totalMoney = 1000
quantity = 3
price = 450

Expected Output:

I have 1000 dollars so I can buy 3 football for 450.00 dollars.

Program:

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))

Output:

I have 1000 dollars so I can buy 3 football for 450.00 dollars.
 

This Particular section is dedicated to Programs only. If you want learn more about Python. Then you can visit below links to get more depth on this subject.