CMSC 201

Lab 6: Functions

For this lab, we're going to have the user enter a number, and the program is going to print out all prime numbers less than that number.

We're going to write three functions:

  1. isPrime(myNum) -- returns whether a number is prime or not.
  2. getPrimes(myNum) -- gets a list of primes less than myNum.
  3. main() -- asks the user for a number, calls getPrimes() with that number as an argument, and prints out the numbers less than that.
Here should be the general structure of your program:

def main():
	#Ask the user for a number
	#Call getPrimes() on that number
	#Print out result

def getPrimes(myNum):
	#Make a temp list
	#For every number from 1 to myNum, check to see if it's prime using the isPrime function.  If it is prime, add it to the temp list
	#Return the temp list

def isPrime(myNum):
	#For every number between 2 and myNum, see if myNum is divisible by that number.
	#If it is divisible by one of these numbers, return false.
	#If you exist the loop, return true.


Sample output:

Please enter a number: 15
[2, 3, 5, 7, 11, 13]