def append_vec():
    print("Please enter a number.")
    tmp = input_float()
    if tmp in vec:
        print("You've already entered this number. Please try another one.")
        return append_vec()
    else:
        vec.append(tmp)
Beispiel #2
0
def temp_conv():
    print("""Press C to convert from Fahrenheit to Celsius.
Press F to convert from Celsius to Fahrenheit.""")
    unit = str(input()).upper()

    if unit == "F":
        print("""Your choice: F
Please enter the temperature in Fahrenheit:""")
        fah = input_float()
        cel = (fah - 32) * 5 / 9
        print(f"The temperature in Celsius is {cel}")
    elif unit == "C":
        print("""Your choice: C
Please enter the temperature in Celsius:""")
        cel = input_float()
        fah = (cel * 9 / 5) + 32
        print(f"The temperature in Fahrenheit is {fah}")
    else:
        return temp_conv()
def calc_bmi():
    print("Press I for Imperial units or M for metric.")
    syst = str(input()).upper()
    if syst == "I":
        print("Please enter your height (first feet, then inches).")
        feet = input_float()
        inches = input_float()
        height = feet * 12.0 + inches
        print("Please enter your weight (lb).")
        weight = input_float()
        bmi = weight / (height**2) * 703.0
        print(f"Your BMI is {round(bmi, 1)}.")
        return bmi
    elif syst == "M":
        print("Please enter your height (cm).")
        height = input_float()
        print("Please enter your weight (kg).")
        weight = input_float()
        bmi = weight / ((height/100.0)**2)
        print(f"Your BMI is {round(bmi, 1)}.")
        return bmi
    else:
        return calc_bmi()
# 12.
# Computing Simple Interest
from inputplus import input_float


def calc_simple_interest(principal, interest, years):
    return principal * (1.0 + interest * years)


print("Enter the principal:")
user_principal = input_float()

print("Enter the rate of interest:")
user_interest = input_float() / 100.0

print("Enter the number of years:")
user_years = input_float()

for i in range(int(user_years) + 1):
    end_amount = round(calc_simple_interest(user_principal, user_interest, i),
                       2)
    print(
        f"After {i} years at {user_interest * 100.0}%, the interest will be worth ${end_amount}."
    )
        if mx < i:
            mx = i
    return mx


def minimum(arr):
    mn = arr[0]
    for i in arr:
        if mn > i:
            mn = i
    return mn


def average(arr):
    return sum(arr) / len(arr)


print("Enter a number:")
usr_inp = input_float()
usr_vec = []

while usr_inp != "done":
    usr_inp, usr_vec = inp_vec(usr_inp, usr_vec)
    usr_inp = add_num()

print(f"""Numbers: {usr_vec}.
The average is {average(usr_vec)}.
The maximum is {maximum(usr_vec)}.
The minimum is {minimum(usr_vec)}.
The standard deviation is {stdev(usr_vec)}""")
Beispiel #6
0
# 26.
# Months to Pay Off a Credit Card

from inputplus import input_float
import math


def calc_months(balance, apr, mpayment):
    rate_p = 1 + apr / 365.0
    bp = math.ceil(100.0 * balance / mpayment) / 100.0
    y = 1.0 + bp * (1.0 - rate_p**30)
    dividend = math.log(y, 2)
    divisor = math.log(rate_p, 2)
    n_months = -1.0 / 30.0 * dividend / divisor
    return n_months


print("What is your balance?")
user_balance = input_float()

print("What is the APR on the card (as percent)?")
user_apr = input_float() / 100.0

print("What is the monthly payment you can make?")
user_mpayment = input_float()

user_nmonths = math.ceil(calc_months(user_balance, user_apr, user_mpayment))

print(f"It will take you {user_nmonths} months to pay off this card.")
Beispiel #7
0
# 11.
# Currency Conversion
from inputplus import input_float
import math, inquirer

xr = {"EUR": 113.0, "USD": 89.0}

question = [
    inquirer.List("currency_choice",
                  message="Please choose currency",
                  choices=["EUR", "USD"],
                  default="EUR")
]

answer = inquirer.prompt(question)
currency = answer["currency_choice"]
pair = "USD" if currency == "EUR" else "EUR"

print("How much money would you like to exchange?")
amount = input_float()
exchanged_amount = math.ceil(amount * xr[currency]) / 100

print(
    f"{amount} {currency} at an exchange rate of {xr[currency]} is {exchanged_amount} {pair}."
)
# Comparing Numbers

from inputplus import input_float

vec = []


def append_vec():
    print("Please enter a number.")
    tmp = input_float()
    if tmp in vec:
        print("You've already entered this number. Please try another one.")
        return append_vec()
    else:
        vec.append(tmp)


print("How many numbers do you want to compare?")
n = int(input_float())

while len(vec) < n:
    append_vec()

maximum = vec[0]

for i in vec:
    if i > maximum:
        maximum = i

print(f"The largest number is {maximum}.")
Beispiel #9
0
tax_rate = {
    "IL": {"empty": 0.08},
    "ILLINOIS": {"empty": 0.08},
    "WI": {
        "EAU CLAIRE": 0.005,
        "DUNN": 0.004
    },
    "WISCONSIN": {
        "EAU CLAIRE": 0.005,
        "DUNN": 0.004
    }
}

print("What is the order amount?")
oa = input_float()

print("What state do you live in?")
state = str(input()).upper()

if state in ["WI", "WISCONSIN"]:
    print("What county do you live in?")
    county = str(input()).upper()
elif state in ["IL", "ILLINOIS"]:
    county = "empty"

tax = math.ceil(100.0 * oa * tax_rate[state][county]) / 100.0
print(f"The tax is ${tax}.")

total = oa + tax
print(f"The total is ${total}.")