. Implement a currency converter application in python
- User
. Implement a currency converter application in python
- Assistant
Here's a simple currency converter application in python:
import requests def convert_currency(amount, from_currency, to_currency): # sending get request to API for converting currency url = 'http://api.exchangerate-api.com/v4/latest/{}' response_from = requests.get(url.format(from_currency)).json() response_to = requests.get(url.format(to_currency)).json() # getting exchange rates for source and target currencies exchange_rate_from = response_from['rates'][to_currency] exchange_rate_to = response_to['rates'][from_currency] # calculating converted currency amount to_amount = amount * exchange_rate_from from_amount = to_amount * exchange_rate_to # rounding off the amount to 2 decimal places to_amount = round(to_amount, 2) from_amount = round(from_amount, 2) return from_amount, to_amount # example usage from_amt, to_amt = convert_currency(1, 'USD', 'INR') print(f'1 USD is equivalent to {from_amt} INR') print(f'1 INR is equivalent to {to_amt} USD') - User
Implement a BMI calculator application in python
- Assistant
Here is a simple BMI calculator application in Python:
def calculate_bmi(weight, height): """ This function calculates the body mass index (BMI) given the weight in kilograms and height in meters. """ bmi = weight / (height ** 2) return bmi weight = float(input("Enter your weight in kg: ")) height = float(input("Enter your height in meters: ")) bmi = calculate_bmi(weight, height) print(f"Your BMI is: {bmi:.2f}") if bmi < 18.5: print("You are underweight") elif bmi < 25: print("You are normal weight") elif bmi < 30: print("You are overweight") else: print("You are obese")In this program,
calculate_bmifunction takes weight and height in kilograms and meters respectively, and calculates the BMI using the formula: weight / (height * height). The:inf"{bmi:.2f}"ensures that the output is rounded to two decimal places.Then we take input from the user for weight and height and call the
calculate_bmifunction with those values. Finally, we print the BMI value along with a message indicating the individual's BMI category based on WHO standards. - User
. Implement a unit converter application in python
- Assistant
- User
Implement a tip calculator application in python
- Assistant
Here is a simple tip calculator application in Python:
def calculate_tip(bill_amount, tip_percent): """ This function calculates the tip amount given a bill amount and tip percentage. """ tip_amount = bill_amount * (tip_percent / 100) return tip_amount bill_amount = float(input("Enter the bill amount: ")) tip_percent = float(input("Enter the tip percentage: ")) tip_amount = calculate_tip(bill_amount, tip_percent) print(f"Tip amount: {tip_amount:.2f}") print(f"Total amount: {bill_amount + tip_amount:.2f}")In this program,
calculate_tipfunction takes bill amount and tip percentage as arguments, and calculates the tip amount using the formula: bill_amount * (tip_percent / 100).Then we take input from the user for bill amount and tip percentage and call the
calculate_tipfunction with those values. Finally, we print the tip amount and the total amount (bill amount + tip amount) with 2 decimal places using f-strings. - User
Implement a loan calculator application in python
- Assistant
Here is a simple loan calculator application in Python:
def calculate_loan_payments(loan_amount, annual_interest_rate, loan_term): """ This function calculates the monthly payment amount for a given loan amount, annual interest rate, and loan term in years. """ months = loan_term * 12 # convert loan term to months monthly_interest_rate = annual_interest_rate / 1200 # convert annual interest rate to monthly rate monthly_payment = (loan_amount * monthly_interest_rate) / (1 - (1 + monthly_interest_rate)**(-months)) return monthly_payment loan_amount = float(input("Enter loan amount: ")) annual_interest_rate = float(input("Enter annual interest rate: ")) loan_term = int(input("Enter loan term in years: ")) monthly_payment = calculate_loan_payments(loan_amount, annual_interest_rate, loan_term) print(f"Monthly payment: ${monthly_payment:.2f}") print(f"Total payment: ${monthly_payment * loan_term * 12:.2f}") - User
Implement a mortgage calculator application in python
- Assistant
- User
Implement a budget calculator application in python
- Assistant
Here is a simple budget calculator application in Python:
def calculate_total_expense(expenses): """ This function takes a list of expenses and calculates the total expense. """ total = sum(expenses) return total def calculate_total_income(incomes): """ This function takes a list of incomes and calculates the total income. """ total = sum(incomes) return total def calculate_budget_balance(incomes, expenses): """ This function takes a list of incomes and expenses and calculates the budget balance. """ total_income = calculate_total_income(incomes) total_expense = calculate_total_expense(expenses) balance = total_income - total_expense return balance # Main program print("Welcome to the Python budget calculator!\n") num_incomes = int(input("Enter the number of income sources: ")) incomes = [] for i in range(num_incomes): income = float(input(f"Enter income {i+1}: $")) incomes.append(income) num_expenses = int(input("Enter the number of expenses: ")) expenses = [] for i in range(num_expenses): expense = float(input(f"Enter expense {i+1}: $")) expenses.append(expense) total_income = calculate_total_income(incomes) total_expense = calculate_total_expense(expenses) budget_balance = calculate_budget_balance(incomes, expenses) print(f"\nTotal income: ${total_income:.2f}") print(f"Total expenses: ${total_expense:.2f}") print(f"Budget balance: ${budget_balance:.2f}")
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.