update,
This commit is contained in:
103
ifkcof/task1/src/main.py
Normal file
103
ifkcof/task1/src/main.py
Normal file
@@ -0,0 +1,103 @@
|
||||
"""
|
||||
ITE3919 - Programming Essentials in Python (Mini Project)
|
||||
Student Name: <<Your Name>>
|
||||
Student No: <<Your Student No.>>
|
||||
"""
|
||||
EURO_RATE = 8.02
|
||||
USD_RATE = 7.75
|
||||
|
||||
|
||||
# from docx,
|
||||
# Assumption
|
||||
# - All user inputs are valid.
|
||||
|
||||
while True:
|
||||
print("Welcome to IBS! Please choose one of the following functions")
|
||||
print("1. Converting Euro or USD to HKD")
|
||||
print("2. Calculating the minimum number of coins")
|
||||
print("3. Calculating the total amount of principle and compound interest")
|
||||
print("4. Quit")
|
||||
|
||||
command = input()
|
||||
|
||||
if command == "1":
|
||||
# add your code of Function 1 here
|
||||
# Converting Euro and US dollars to Hong Kong Dollar
|
||||
# When user chooses this function, user can convert Euro or USD to HKD.
|
||||
# User inputs strings "Euro" or "USD" to choose to convert Euro to HKD or USD to HKD respectively. Then, the program asks the user to input the amount of Euro or USD.
|
||||
# After the users input the amount, the program shows the amount of HKD.
|
||||
|
||||
# Assume the user will input valid strings (i.e. "Euro" and "USD")
|
||||
print("Currency to be converted to HKD (Euro / USD): " , end="")
|
||||
currency = input()
|
||||
|
||||
print("Amount to be converted: " , end="")
|
||||
amount = float(input())
|
||||
|
||||
# init converted amount
|
||||
converted_amount = amount
|
||||
|
||||
# from Docx, Assume the user will input valid strings (i.e. "Euro" and "USD")
|
||||
if currency == "Euro":
|
||||
converted_amount = float(amount) * EURO_RATE
|
||||
else:
|
||||
converted_amount = float(amount) * USD_RATE
|
||||
|
||||
print("{:.1f} {} = {:.1f} HKD".format(float(amount), currency, float(converted_amount)))
|
||||
|
||||
elif command == "2":
|
||||
# add your code of Function 2 here
|
||||
# Calculating the minimum number of coins for corresponding amounts of dollars
|
||||
# When user chooses this function, the program calculates the minimum number of coins for corresponding amounts of dollars.
|
||||
# User inputs an amount, then the program shows the minimum number of 10-dollar coins, 5-dollar coins, 2-dollar coins and 1-dollar coins.
|
||||
|
||||
print("Input an amount: ", end="")
|
||||
amount = int(input())
|
||||
|
||||
print("The minimum numbers of coins for {} dollars are: ".format(amount))
|
||||
|
||||
# number of coins = quotient get divided by 10
|
||||
ten_dollar_coins = amount // 10
|
||||
remaining_amount = (amount - (ten_dollar_coins * 10))
|
||||
|
||||
# number of coins = quotient get divided by 5
|
||||
five_dollar_coins = remaining_amount // 5
|
||||
remaining_amount = (remaining_amount - (five_dollar_coins * 5))
|
||||
|
||||
# number of coins = quotient get divided by 2
|
||||
two_dollar_coins = remaining_amount // 2
|
||||
remaining_amount = (remaining_amount - (two_dollar_coins * 2))
|
||||
|
||||
one_dollar_coins = remaining_amount
|
||||
|
||||
print("10-dollar coin(s): {}".format(ten_dollar_coins))
|
||||
print("5-dollar coin(s): {}".format(five_dollar_coins))
|
||||
print("2-dollar coin(s): {}".format(two_dollar_coins))
|
||||
print("1-dollar coin(s): {}".format(one_dollar_coins))
|
||||
|
||||
elif command == "3":
|
||||
# add your code of Function 3 here
|
||||
# Calculating the total amount of principle and compound interest
|
||||
|
||||
# When user chooses this function, the program calculates the compound interest based on the inputted principle, interest rate and number of years compounded.
|
||||
# User inputs principle, interest rate and number of years compounded, the program shows the total amount of principle and compound interest.
|
||||
|
||||
print("Input principle: ", end="")
|
||||
principle = float(input())
|
||||
|
||||
print("Input interest rate: ", end="")
|
||||
intrest_rate = float(input())
|
||||
|
||||
print("Input number of years compounded: ", end="")
|
||||
years = int(input())
|
||||
|
||||
# init total amount
|
||||
total_amount = principle
|
||||
for i in range(0, years):
|
||||
total_amount = total_amount + (total_amount * (intrest_rate))
|
||||
|
||||
print("The total amount of principle and compound interest: {}".format(total_amount))
|
||||
|
||||
elif command == "4":
|
||||
print("Thanks for using IBS! Bye!")
|
||||
break
|
Reference in New Issue
Block a user