Question: PYTHON - Odds or Evens Part 1 - Pick odds or evens Create a new Python file called OddsAndEvens.py. Add a main method. Add a

PYTHON - Odds or Evens

Part 1 - Pick odds or evens

  1. Create a new Python file called OddsAndEvens.py.
  2. Add a main method.
  3. Add a print function that produces the following text on the console.

Lets play a game called Odds and Evens

  1. Ask the user for their name and then upon entering their name store it in a variable to be used in interacting with the user.

What is your name?

  1. Now greet the user and ask them to choose either odds or evens. Let the user type in either O or E.

Hi name, which do you choose? (O)dds or (E)vens?

  1. Using an if/else statement print out whether the user chose odds or evens.

name has picked odds! The computer will be evens.

Or

name has picked evens! The computer will be odds.

  1. Finally add a print that produces a series of - characters to separate this stage from the others in your output.

Part 2 - Play the Game

Now you are going to be adding the actual game play to your game.

  1. Ask the user how many fingers they are going to play, and let them enter in a number.

How many fingers do you put out?

  1. Add the following code to your program to let the computer choose a random number to represent their fingers:

import random

number = random.randint(0, 5);

  1. Add a print that tells the user how many fingers the computer played.

The computer plays number fingers.

  1. Add another line of - characters to separate this part of your output from the results.
  2. Now you need to determine what the results are.
  • Add the users number and the computers numbers together to get the sum.
  • Add a print that will print out the math to show the user.

Sum = userNumber + computerNumber

  • Now you need to figure out if the sum is odd or even. You can use the % or mod operator to do so. The mod operator returns the reminder, any number % 2 with a remainder of 0 (meaning it is perfectly divisible by 2) is even, any number % 2 with a remainder of 1 is odd. Here is the code you can use:

oddOrEven = sum % 2

oddOrEven will be true if sum us even, it will be false if sum is odd.

  • Now use an if/else statement to print out whether sum was odd or even.
  1. Add another line of - characters to end your program.

Part 3 - Who won?

Now that we know the results, its time to decide who the winner is!

Inside your if/else statement that prints out odd or even you are going to add another set of if/else statements to tell who the winner is, based on what the player chose back in stage 1. Here is some pseudo code (notation resembling simplified code, not real code) that you can use to write the real code.

if (the sum was even)

print out even

if (the user chose evens)

the user wins

else

the computer wins

else

// inverse of above if statement

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related General Management Questions!