PYTHON – ASSIGNMENT #12: TEMPERATURE CONVERSION …

PYTHON ? ASSIGNMENT #12: TEMPERATURE CONVERSION

Scenario: You will create a Python program that, using functions, will take a temperature and convert it from Fahrenheit-to-Celsius or Celsius-to-Fahrenheit and then display the results to the screen.

Instructions: You will need to prompt the user for a temperature and what temperature scale we're converting to. Finally, you will need to display the converted temperature to the screen.

Formulas Needed:

a. To convert from degrees Fahrenheit to degrees Celsius:

(temperature_fahrenheit ? 32) x 5.0 / 9.0

b. To convert from degrees Celsius to degrees Fahrenheit:

9.0 / 5. 0 x temperature_celsius + 32

Variables Needed (minimum):

a. name ? to hold the name of the person you are working with

b. temp ? to hold the temperature the user wants converted (should be capable of holding a decimal)

Functions Needed:

a. fahrenheit_to_celsius()

This method receives the fahrenheit temperature to be converted, does the math, and returns the answer in celsius

b. celsius_to_fahrenheit()

This method receives the celsius temperature to be converted, does the math, and returns the answer in fahrenheit

c. display_temp()

This method receives a String that is to be printed to the screen with the converted answer. You will need to pass to this method the persons name, the temperature they initially entered, and the converted temperature. This method has no return.

(over)

PYTHON ? ASSIGNMENT #12: TEMPERATURE CONVERSION

d. display_menu()

This method will display a simple menu to the screen. This method will return the option the user has selected

e. get_name()

This method will prompt the user for their name. This method will return the name the user has entered

Example #1 of Program Execution:

Enter your name: John Doe Menu - Select one of the options below:

1. Convert from Fahrenheit to Celsius 2. Convert from Celsius to Fahrenheit Selection: 1 John Doe you have choosen to convert Fahrenheit to Celsius. Enter your temperature: 78.5 John Doe 78.5 degrees Fahrenheit is 25.83 degrees Celsius.

Example #2 of Program Execution: Enter your name: John Doe Menu - Select one of the options below:

1. Convert from Fahrenheit to Celsius 2. Convert from Celsius to Fahrenheit Selection: 2 John Doe you have choosen to convert Celsius to Fahrenheit. Enter your temperature: 100 John Doe 100 degrees Celsius is 212 degrees Fahrenheit.

TEST DATA

(Can be used for both fahrenheit to celsius or celsius to

fahrenheit)

Fahrenheit

Celsius

32

0

50

10

145

62.78

PYTHON PROGRAM #13: CAESARCIPHER

Julius Caesar created a cryptology method many years ago. He would take the regular alphabet and add a "cipher key" to it so that the enemy could not decipher his messages if it were to fall in their hands.

For example, if the "cipher key" were 3, then the letter "A" would be "D", the letter "B" would be "E" and so on . . .

You are to create a program that will prompt the user to see if he/she wants to encode or decipher a message. Once the user has entered their choice, prompt the user for the String to either encode or decipher and display those results to the screen. For now, assume we are using a "cipher key" of 3.

Create two (2) Python dictionaries with key-value pairs to solve the problem in your program (one for encrypting and the other for decrypting). Limit your message lengths to no more than 20-characters.

Example Program Run #1:

Would you like to: 1. Encrypt a message 2. Decipher a message Choice: 1

Enter your message to be encrypted: MEET YOU AT THE ZOO Your encrypted message is: PHHW BRX DW WKH CRR

Example Program Run #2:

Would you like to: 1. Encrypt a message 2. Decipher a message Choice: 2

Enter your message to be decrypted: PHHW BRX DW WKH CRR Your decrypted message is: MEET YOU AT THE ZOO

PYTHON PROGRAM #14: CAESARCIPHERMODIFIED

You have already created a CaesarCipher for a fixed "shift-key". Now we are going to make you think a little harder . . .

Create a new CaesarCipher program called CAESARCIPHERMODIFIED that will allow the user to enter a "shift-key" value between 1 and 13 inclusive. Encrypt and decipher your message based on the "shift-key" the user enters.

Example Program Run #1:

Would you like to: 1. Encrypt a message 2. Decipher a message Choice: 1

Enter your message to be encrypted: MEET YOU AT THE ZOO Enter your shift-key: 3 Your encrypted message is: PHHW BRX DW WKH CRR

Example Program Run #2:

Would you like to: 1. Encrypt a message 2. Decipher a message Choice: 2

Enter your message to be decrypted: PHHW BRX DW WKH CRR Enter your shift-key: 3 Your decrypted message is: MEET YOU AT THE ZOO

Name: ______________________________________

Class: 1B or 2B

PYTHON ASSIGNMENT ? COIN TOSS

Directions: Create a program called "Coin Toss" that simulates flipping a coin. You will prompt the user for the number of times to "flip the coin" and, using the random number generator, keep track of the number of times heads and tails occur.

1. Write the Python code in the space provided to complete the following:

a. Line #1: Comment with your name b. Line #2: Comment that says "Python Program ? Coin Toss"

2. Prompt the user for the number of times to flip the coin

3. Using a loop, flip the coin keeping track of the number of heads and tails each time the

coin is flipped

4. Display your results to the screen as shown below. NOTE: Your results do not have to be the same as the results listed below.

Example of Program Run #1:

How many times do you want to flip? 10

Results: Heads - 7 Tails - 3

Example of Program Run #2:

How many times do you want to flip? 100

Results: Heads - 48 Tails - 52

Answer the following question and turn in this sheet with your name on it:

Q. In the first program run example, we had a lot more heads than tails. In the second program run, the results were almost even. Why?

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download