Interest Calculator

Write a short program that:

  1. Asks the user for their name.
  2. Asks the user for their savings account balance.
  3. Asks the user for their monthly interest rate.
  4. Calculates the interest they will receive after one month: balance * interest_rate
  5. Displays the output to the user, using their name and formatting the interest as a dollar amount.

An example run is:

Please enter your name: Zeus
Please enter your balance: 100
Please enter your monthly interet rate: .02
Your interest after one month is $2.00.

Roman Numerals

Write a program that prompts the user to enter a number within the range of 1 through 10. The program should display the Roman numeral version of that number. If the number is outside the range of 1 through 10, the program should display an error message. The following table shows the Roman numerals for the numbers 1 through 10:

Number Roman Numeral
1 I
2 II
3 III
4 IV
5 V
6 VI
7 VII
8 VIII
9 IX
10 X

There are some more elegant ways to implement this, such as using dicts, but for now use if statements.

Body Mass Index

Write a program that calculates and displays a person's body mass index (BMI). The BMI can be used to determine whether someone is overweight or underweight for their height. A person's BMI is calculated with the formula:

BMI = weight * 703 / height2

where weight is measured in pounds and height is measured in inches.

The program should ask the user to enter their weight and height, then display the user's BMI. The program should also display a message indicating whether the person has optimal weight, is underweight, or overweight. Use the following guidelines:

Lists

How do you think you'd find the second largest value in a list?

When introducing for loops, one example was counting the number of vowels in text (program duplicated below). How could we simplify the code by using a list?

value = input("Enter text: ")
count = 0 #number of vowels in value
for letter in value:
    if letter == 'a' or letter == 'e' or letter == 'i' or letter == 'o' or letter == 'u':
        count += 1

print("There are", count, "lowercase vowels in the text you entered.")

How would you find the index of the largest element in the list?

The index method only finds one occurrence. Write code that finds the index of all occurrences of a value. Store the indices in a list.

Given a list of numbers, add up all of the numbers at even positions. Try writing this in one line of code.

The split function breaks a string into a list of strings. What if that string were a list of numbers (e.g. '12.3, 14.8, 9.2, 12.6'). How could you convert it into a list of numbers?

The join function converts a list of strings into one string. How could you use join to convert a list of numbers into a string?

List Comprehension

Use list comprehension (and common list functions) to transform this code into one line:

numbers = [1, 2, 3, 4, 5]
squared = []
for val in numbers:
    squared.append(val*val)

Write a program that asks the user for text. After the user entered text, count the number of words starting with a vowel (ignore capitalization) and print out the result. Write this program using only three lines of code (this can actually be done in less than three).