Programming Exercises

P1:

Write a Python function named zeroCheck that is given three integers, and returns true if any of the integers is 0, otherwise it returns false.

In [ ]:

P2:

Write a Python function named ordered3 that is passed three integers, and returns true if the three integers are in order from smallest to largest, otherwise it returns false.

In [ ]:

P3:

Write a Python function named modCount that is given a positive integer, n, and a second positive integer, m <= n, and returns how many numbers between 1 and n are evenly divisible by m.

In [ ]:

P4:

Write a Python function named helloWorld that displays "Hello World, my name is <name> ", for any given name passed to the routine.

In [ ]:

P5:

Write a Python function named printAsterisks that is passed a positive integer value n, and prints out a line of n asterisks. If n is greater than 75, then only 75 asterisks should be displayed.

In [ ]:

P6:

Implement a Python function that is passed a list of numeric values and a particular threshold value, and returns the list with all values above the given threshold value set to 0. The list should be altered as a side effect to the function call, and not by function return value.

In [ ]:

P7:

Write a Python function named getContinue that displays to the user “Do you want to continue (y/n): ”, and continues to prompt the user until either uppercase or lowercase 'y' or 'n' is entered, returning (lowercase) 'y' or 'n' as the function value.

In [ ]:

Development Problems

D1: Metric Conversion Program

Develop and test a Python program that allows the user to convert between the metric measurements of millimeter, centimeter, meter, kilometer, and inches, feet, yards, and miles. The program should be written so that any one measurement can be converted to the other.

In [ ]:

D2: GPA Projection Program

Develop and test a Python program that lets the user enter their current cumulative GPA, their total credits earned, and the number of credits they are currently taking. The program should then request from the user a target cumulative GPA that they wish to achieve, and display the GPA of the current semester needed to achieve it.

In [ ]:

D3: Tic-Tac-Toe Two-Player Program

Develop and test a Python program that lets two players play tic-tac-toe. Let player 1 be X and player 2 be O. Devise a method for each player to indicate where they wish to place their symbol. The program should terminate if either there is a winner, or if the game results in a tie. The tic-tac-toe board should be displayed after every move as shown below.

                                            X  -  X
                                            O  O  -
                                            X  X  O

In [ ]:

D4: Tic-Tac-Toe Automated Play *

Develop and test a Python program that plays tic-tac-toe against the user. Develop an appropriate strategy of play and implement it in your program. The program should be designed to allow the user to continue to play new games until they decide to quit. The program should display the total number of wins by the computer versus the player at the start of each new game.

In [ ]: