Labs - chad-p/wiki-python-class GitHub Wiki

Labs

Odd or Even

Goal

Write a program that asks for a number and outputs if the number is odd or even.

Example

Give me a number: 5
> Your number 5 is an odd number.
  • Hint: What does Modulus do again?

Solution

Please view the solution after you have attempted it on your own.

Guess the Number

Goal

Write a program that picks a random number from 1-10. Then ask a user to guess the number. Output if the guess was correct or not.

Example

I'm thinking of a number between 1-10, what is it?  5
> Sorry, the number was 7.
  • Hint: There a library that can pick a random number.

Solution

Please view the solution after you have attempted it on your own.

Rock Paper Scissors

Goal

Write a program that plays the game rock, paper, scissors with a user.

Have your program generate a random answer for the computer, but don't display it. Then, ask the player for their answer.

  • Paper wins over Rock
  • Rock wins over Scissors
  • Scissors win over Paper

Example

Ready to play Rock Paper Scissors?
What do you pick?  Rock
> I choose Scissors.  You won!
  • Bonus: Do this in a loop. Best of 3.

Solution

Please view the solution after you have attempted it on your own.

Planet Weights

Goal

You can calculate an individual's weight on another planet by multiplying their weight times the relative surface gravity of the other world.

Weight on Other Planet = Weight on Earth x Multiple of Earth’s Gravity

Design a Python program that asks a user for their name and weight. The program will greet the user by name and then calculate/display the user's weight on the other planets. Each item should be displayed on a line by itself.

Use the following values for the conversions

  • Body - Multiple of Earth's Gravity
  • Sun - 27.01
  • Mercury - .38
  • Venus - .91
  • Earth - 1
  • Moon - .166
  • Mars - .38
  • Jupiter - 2.34
  • Saturn - 1.06
  • Uranus - .92
  • Neptune - 1.19
  • Pluto - .06

Example:

Example

Solution

Please view the solution after you have attempted it on your own.

Tip Calculator

Goal

  • Given a tax rate of %8.75, prompt user for cost of a meal and how much to tip as a percentage.
  • Output to user this information.
    • Cost of meal
    • Cost of tax
    • Cost of tip
    • Total Meal Cost

Example

Example

Solution

Please view the solution after you have attempted it on your own.