| CMSC 201 |
Lab 6: FunctionsFor 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:
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] |