← Previous Module 1: Variables, Input/Output, and Basic Math Next →
Statement
Solution

Python Exercise 1.3: Currency Converter

Create a Python program that converts US Dollars (USD) to your local currency.

Your program should:

  • Create a variable for the Exchange Rate (e.g., set it to a fixed number like 84.50).
  • Ask the user to input an amount in USD (float).
  • Calculate the converted amount by multiplying the USD amount by the Exchange Rate.
  • Print the result clearly.

Note: You can choose any currency (INR, EUR, GBP). For this exercise, assume the rate is fixed.

Sample Interaction:

Input
Output
50
Enter amount in USD: 50 -------------------- Exchange Rate: 84.5 50.0 USD is equal to 4225.0 in Local Currency

Solution

Here is how you can solve this using basic float multiplication and f-strings.

# 1. Define Exchange Rate # (Example: 1 USD = 84.50 INR) rate = 84.50 # 2. Get User Input # We use float() because money can have decimals usd_amount = float(input("Enter amount in USD: ")) # 3. Calculate Conversion converted_amount = usd_amount * rate # 4. Print Output print("-" * 20) print(f"Exchange Rate: {rate}") print(f"{usd_amount} USD is equal to {converted_amount} in Local Currency")

Key Concepts:

  • float() is used instead of int() because currency often involves decimal points (cents/paisa).
  • Variables store values (like rate) that can be reused in calculations.
  • Basic math operators (*) work on both integers and floats.
Python 3
Test Console
Run code to see output...

Scroll to Top