Week 3 - Exercises

Exercise 1 - First module

This week we are going to write a module and import some functions from it.

For the code below to work, you need to do the following:

  1. Create a file called mymodule.py and put it in the same folder as this notebook. It me be easiest to do this in Spyder.

  2. Write the three functions that are to be imported from mymodule. Note that these are the three scripts from the first week, but they will need to be implemented in the module as functions.

The desired output is as follows. First, we play the number guessing game, which should return the secret number at the end. Then, we check whether that number is a prime number. Finally, we pretend that the number is a temperature in degrees Fahrenheit and report the equivalent in Celsius.

There are many ways to approach this problem, but the output should look something like below.

[1]:
from mymodule import (
    guess_the_number,
    check_prime_number,
    fahrenheit_to_celsius
)

# Play the number guessing game
number = guess_the_number()

# Check whether the secret number is a prime
check_prime_number(number)

# If the number was a temperature in degrees Fahrenheit,
# report the equivalent in Celsisus
fahrenheit_to_celsius(number)
Let's play a guessing game!

Enter any whole number between 1 and 100:  50
Too low
Enter number again:  75
Too low
Enter number again:  90
Too high!
Enter number again:  83
Too high!
Enter number again:  82
Too high!
Enter number again:  81
Too high!
Enter number again:  80
Too high!
Enter number again:  78
You guessed it right!!

Checking to see if 78 is a prime number.
        Testing for 2
78 is divisible by 2, so it is not a prime number.
78 degrees fahrenheit is equivalent to 25.56 degrees celsius.