# 15B: Python Pushups
**Source**: https://cscircles.cemc.uwaterloo.ca/15b-python-pushups/
**Parent**: https://cscircles.cemc.uwaterloo.ca/
*Exercises 15A, 15B, and 15C can be completed in any order.*
In this lesson, we give several medium-size exercises combining tools learned in earlier lessons.
Coding Exercise: Forty Below In The Winter
In this exercise, you will create a temperature converter which will convert Fahrenheit values to Celsius and vice-versa. You will need the following two formulas which relate the temperature *f* in Fahrenheit to the temperature *c* in Celsius:
The input will be a string consisting of a floating-point number followed immediately by the letter F or C, such as "`13.2C`". You should convert to the other temperature scale and print the converted value in the same format. For example, if the input is "`8F`" then the output should be (approximately) "`-13.333C`", and if the input is "`12.5C`" then the output should be "`54.5F`".
You need to create an account and log in to ask a question.
# delete this comment and enter your code here
You may enter input for the program in the box below.
| | | | |
| --- | --- | --- | --- |
| | | | |
More actions...
History
Help
Coding Exercise: Credit Check
You have been hired by MeisterCard to write a function which checks if a given credit card number is valid. Your function `check(S)` should take a string `S` as input. First, if the string does not follow the format `"#### #### #### ####"` where each `#` is a digit, then it should return `False`. Then, if the sum of the digits is divisible by 10 (a "checksum" method), then the procedure should return `True`, else it should return `False`. For example, if `S` is the string "`9384 3495 3297 0123`" then although the format is correct, the digit sum is 72 so you should return `False`.
You need to create an account and log in to ask a question.
def check(S):
# delete this comment and enter your code here
Enter testing statements like `print(myfunction("test argument"))` below.
| | | | |
| --- | --- | --- | --- |
| | | | |
More actions...
History
Reset code to default
Help
In the next exercise, use the methods `string.split()`, which removes the spaces from a word and returns a list of the words it contains, and `string.lower()` which converts a string to lower case. For example,
- `"Split these words!".split()` returns the list `["Split", "these", "words!"]`
- `"LOWERCase".lower()` returns `"lowercase"`
Note: `split()` can accept further options to split in other ways; see the [documentation](http://docs.python.org/py3k/library/stdtypes.html#str.split).
Coding Exercise: Poetic Analysis
A writer is working on their newest poem, *Turing and the Machines*. They have hired you to determine the word which appears the most times. You can access the lines of the poem by calling `input()` repeatedly, and the last line contains the three characters `###`. All lines consist of words separated by single spaces; there are no digits or punctuation. Convert all the words to lower-case, and **print the word that occurs the most times** (we guarantee there will not be a tie). For example, if the input is
```
Here is a line like sparkling wine\
Line up fast or be the last\
###
```
Then the output should be
```
line
```
since it appears twice and no other word appears twice.
You need to create an account and log in to ask a question.
# delete this comment and enter your code here
You may enter input for the program in the box below.
| | | | |
| --- | --- | --- | --- |
| | | | |
More actions...
History
Help