Write a short program that:
An example run is:
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 dict
s, but for now use if statements.
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:
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:
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?
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?
Use list comprehension (and common list functions) to transform this code into one line:
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).