build a calculator and calendar and currency converter app
- User
build a calculator and calendar and currency converter app
- Assistant
build a calculator and calendar and currency converter app
Sure! I can help you build a simple Calculator, Calendar, and Currency Converter app. Since building all in one full project can get quite large, I’ll provide a starting point for each in Python with basic functionality. You can expand or integrate them later in a GUI app using libraries like Tkinter if you want.
def calculator():
print("Simple Calculator")
print("Operations: +, -, *, /")
num1 = float(input("Enter first number: "))
op = input("Enter operator (+, -, *, /): ")
num2 = float(input("Enter second number: "))
if op == '+':
result = num1 + num2
elif op == '-':
result = num1 - num2
elif op == '*':
result = num1 * num2
elif op == '/':
if num2 == 0:
print("Error: Division by zero.")
return
result = num1 / num2
else:
print("Invalid operator.")
return
print(f"Result: {result}")
if __name__ == "__main__":
calculator()
Run this script and you get a basic interactive calculator.
Using Python’s calendar module:
import calendar
from datetime import datetime
def show_calendar():
now = datetime.now()
year = now.year
month = now.month
cal = calendar.TextCalendar(calendar.SUNDAY)
print(cal.formatmonth(year, month))
if __name__ == "__main__":
show_calendar()
This prints the current month's calendar in the terminal.
We'll use an API, for example ExchangeRate-API or exchangerate.host (free). Here's a simple example using requests and exchangerate.host:
import requests
def currency_converter():
print("Currency Converter")
from_currency = input("From currency (e.g., USD): ").upper()
to_currency = input("To currency (e.g., EUR): ").upper()
amount = float(input("Amount to convert: "))
url = f"https://api.exchangerate.host/convert?from={from_currency}&to={to_currency}&amount={amount}"
response = requests.get(url)
if response.status_code != 200:
print("Failed to retrieve exchange rate.")
return
data = response.json()
if data['success']:
result = data['result']
print(f"{amount} {from_currency} = {result:.2f} {to_currency}")
else:
print("Conversion failed. Check currency codes.")
if __name__ == "__main__":
currency_converter()
Make sure you have requests installed:
pip install requests
import calendar
from datetime import datetime
import requests
def calculator():
print("\nSimple Calculator")
print("Operations: +, -, *, /")
num1 = float(input("Enter first number: "))
op = input("Enter operator (+, -, *, /): ")
num2 = float(input("Enter second number: "))
if op == '+':
result = num1 + num2
elif op == '-':
result = num1 - num2
elif op == '*':
result = num1 * num2
elif op == '/':
if num2 == 0:
print("Error: Division by zero.")
return
result = num1 / num2
else:
print("Invalid operator.")
return
print(f"Result: {result}")
def show_calendar():
print("\nCurrent Month Calendar")
now = datetime.now()
year = now.year
month = now.month
cal = calendar.TextCalendar(calendar.SUNDAY)
print(cal.formatmonth(year, month))
def currency_converter():
print("\nCurrency Converter")
from_currency = input("From currency (e.g., USD): ").upper()
to_currency = input("To currency (e.g., EUR): ").upper()
amount = float(input("Amount to convert: "))
url = f"https://api.exchangerate.host/convert?from={from_currency}&to={to_currency}&amount={amount}"
response = requests.get(url)
if response.status_code != 200:
print("Failed to retrieve exchange rate.")
return
data = response.json()
if data['success']:
result = data['result']
print(f"{amount} {from_currency} = {result:.2f} {to_currency}")
else:
print("Conversion failed. Check currency codes.")
def main():
while True:
print("\nChoose an option:")
print("1. Calculator")
print("2. Calendar")
print("3. Currency Converter")
print("4. Exit")
choice = input("Enter choice (1-4): ")
if choice == '1':
calculator()
elif choice == '2':
show_calendar()
elif choice == '3':
currency_converter()
elif choice == '4':
print("Goodbye!")
break
else:
print("Invalid choice. Try again.")
if __name__ == "__main__":
main()
If you want, I can help you create GUI versions for any or all of these apps! Just ask.
Not yet included in a published release.