-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat_bot.py
More file actions
38 lines (30 loc) · 1.29 KB
/
Copy pathchat_bot.py
File metadata and controls
38 lines (30 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
def ask_name():
name = input("What is your name ? ").capitalize()
return name
def calculate_expenses(expenses):
sum_total = sum(expenses)
return sum_total
def calculate_savings(income, expenses):
"""Subtracts expenses from income to calculate savings."""
savings = income - expenses
return f"Total savings: ${savings: .2f}"
def simple_interest(principal, rate, time):
"""Calculate simple interest on a principal over time at a given rate."""
interest = principal * (rate / 100) * time
return f"Simple interest: ${interest: .2f}"
def compound_interest(principal, rate, times_compounded, years):
"""Calculate compound interest."""
amount = principal * (1 + (rate / 100) / times_compounded) ** (times_compounded * years)
interest = amount - principal
return f"Compound interest: ${interest: .2f}"
command = input("Which command would you like to run? Options: expenses, ask_name, simple_interest, compound_interest ")
if command == "expenses":
print(calculate_expenses(exp))
elif command == "ask_name":
ask_name()
elif command == "compound_interest":
pricipal = input("What is the principal? ")
rate = input("What is the rate? ")
compound_interest()
else:
print("invalid comment ")