User:Sruthijakkampudi/sandbox

Assignment: Courses/CS 1114/Lab Manual/Python Functions That Returns a Value/Homework

The following problem is to be completed on your own and before your next lab.

Create a Python script, cpFunctionsHW.py, and include functions for the following problems along with code to test the functions.

1. Create a function called calcRelPrime to find whether given two numbers are Relatively Prime or not. The user should be prompted for Two Numbers outside of the function. The result should be returned and then output to the screen. NOTE: Two integers a and b are said to be relatively prime if the only positive integer that evenly divides both of them is 1. That is, the only common positive factor of the two numbers is 1.

For example, 14 and 15 are Relatively Prime, being commonly divisible by only 1, but 14 and 21 are not, because they are both divisible by 7.

2. Create a function called diceGuessing to play a simple guessing game with the user. The algorithm is: Guessing Game Begin Algorithm Have the computer pick a random number from 1 to 6. Call it secretNum. Allow user to guess a number (input it). Call it guessedNum. As long as guessedNum is not equal to secretNum, Tell the user they guessed incorrectly, allow the user to guess a new number. Store it in guessedNum. Once the correct number was guessed, congratulate the user. End Algorithm

To have Python generate a random number, you first need to import the random module. Then you can use the random.randint(lo,hi) function to get a random number in between lo and hi (inclusive). So for this problem, to pick secretNum, you could use the line of code: secretNum = random.randint(1,6) Don't forget to place the statement import random at the top of your program!

3. Create a function called fibonacciSequence to display the Fibonacci sequence up to Nth term.The user should be prompted for N outside of the function. The result of series should be printed to the screen.

When you have completed and tested the program, submit the source code by using the course submission utility. If you have any difficulty in completing this assignment, be sure to get help from your instructor.

Spend enough time with pencil and paper to satisfy yourself that you truly understand the problem and can work examples by hand before starting to write program code; you cannot explain a solution to a computer if you do not understand it yourself. If you find you do not understand a problem well enough to work examples by hand, seek out input from your instructor or fellow classmates; discussion with classmates can be particularly rewarding for both parties (as long as collaboration stops here). Start as early as you can to give yourself every opportunity to think through a solution; starting close to the deadline increases pressure on you and can make it even harder to think.

FOR HOMEWORK CREDIT: Upload the following file: cpFunctionsHW.py