Python 3 Evens and Odds Evens and Odds is a classic games used to determine who
ID: 3887541 • Letter: P
Question
Python 3
Evens and Odds Evens and Odds is a classic games used to determine who goes to lunch, or takes out the trash, or buys the next round. It is similar to Rock, Paper, Scissors. You play against a single opponent, one player declares Even or Odd, and then both players shoot. Shooting is the act of showing the other player how many fingers are in play. You can decide to show 1-5 fingers, and your total plus the other persons is used to determine even or odd. If I declare Odd, and I throw 3, and the other person throws 1, then the total is 4, and even number. Since I chose odd I lost. Our program will allow user to play multiple rounds in a row. They will also have the option to consider a round a group of best 2 out of 3. Single play is when a single trial of even or odd determines the round. Best 2 out of 3 awards the round to whoever, wins 2 trials first. Functional Decomposition You are going to be required to create functions in this program. Functions will help you break down the program into smaller portions. You will be required to implement and use the following functions as given, with the arguments given. These are to help you get started and give you an idea of what to do. Remember, functions can also make it easier to test. choose_number() - This function returns an integer from 1 to 5 inclusive (1, 5). It will continually ask the user for a number. We don’t expect the user to give anything other than an integer, but this function should continually ask for input until they finally provide a valid integer. If they do not enter valid input it will continually ask them until they do.
Example >>> value = choose_number() Enter a number from 1 to 5 ( inclusive ) ==> 10 You must choose a value between 1 and 5 only Enter a number from 1 to 5 ( inclusive ) ==> 0 You must choose a value between 1 and 5 only Enter a number from 1 to 5 ( inclusive ) ==> 6 You must choose a value between 1 and 5 only Enter a number from 1 to 5 ( inclusive ) ==> 5 >>> value 5 >>>
Choose_even_or_odd() - This function takes no arguments and returns a boolean ( True or False). It returns True if the user choses even, and False if they do not. is_match(even : boolean, user1_number : int, user2_number : int) - This function has 3 arguments and returns a boolean. Even indicates if the player choose the result to be even or odd. It’s True if they choose even, False if they had chosen odd. The function returns True if the result matches their prediction. If the numbers add up to an even number and the even is True, then the function returns true. choose_number_of_rounds() - This function takes no arguments and returns an integer. It will continually ask the user for an integer input from 3 - 15, inclusive. ( 3, 15). Very much like the function above. ( Since these functions are so similar, you may want to think of a way to make one function that does the work of both. What would you pass to this function? ) You’ll want to implement more functions and will be graded on those that you provide. You MUST provide at LEAST 2 more functions. In reality keep breaking problems down into smaller sections until you know how to write that portion. Make it a function, and then you can simply call it to do the work you have created and understood.
Explanation / Answer
def choose_number():
value = int(input("Enter a number from 1 t 5: "))
while (value > 5 or value < 1):
print("You must choose a value between 1 and 5 only")
value = int(input("Enter a number from 1 t 5: "))
return value
def choose_ever_or_odd():
num=choose_number()
if(num%2==0):
return True
else:
return False
def is_match(choise, num1, num2):
s = num1 + num2
if (s%2==0):
if(choise == "even"):
return True
else:
return False
elif(s%2 != 0):
if(choise == "odd"):
return True
else:
return False
else:
return False
def choose_number_of_rounds():
rounds = int(input("Enter a number of rounds(3-15 only):"))
while (value > 15 or value < 3):
print("You must choose a value between 3 and 15 only")
rounds = int(input("Enter a number of rounds(3-15 only):"))
return rounds
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.