Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Challenge 8

This challenge is intended to be taken after the modules section.

Problem 1: Custom Module

  1. Create a new file called greetings.py.
  2. In greetings.py, define a function called say_hello(name) that returns a string "Hello, {name}!".
  3. In the editor below, import the greetings module and use the say_hello function to greet a user.
# Assume greetings.py exists
# Your code here

Problem 2: Using the math module

  • Ask the user to enter the radius of a circle.
  • Use the math module to get the value of PI and to calculate the area of the circle (Area = π * r^2).
  • Print the calculated area.

Problem 3: Number Guessing Game

  • Use the random module to generate a random integer between 1 and 100.
  • Create a loop that asks the user to guess the number.
  • After each guess, tell the user if their guess was too high or too low.
  • The loop should end when the user guesses the correct number.


Contributors: