Question: Below is the criteria for a python 3 assignment. I have most of the code written but when either the player or the computer wins

Below is the criteria for a python 3 assignment. I have most of the code written but when either the player or the computer wins the game and it asks if you want to play again, the No answer works fine but the Yes answer doesn't repsond appropriately. Can someone help me out?

Greedy Coins Game

Greedy Coins is a simple two player coin game, played by flipping 3 coins. The first player to reach or surpass 20 is the winner. Each player takes turns flipping the 3 coins, they add to the pot with each turn, having to decide to flip again and increase the pot, or cash out. The risk being they could lose the amount theyve accumulated into the pot.

The Rules for each player flip.

Flip the 3 coins.If there are no heads ( all tails ),

The pot gets set to zero

The other player goes to step 1.

The number of heads is added to the pot.

User can choose to hold or flip again.

Choice FLIP. Return to Step 1.

Choice HOLD.

Increment Player score by the pot amount.

Pot gets set to 0.

Second player gets to flip and goes to Step 1.

Program Requirements:

Before each opponent begins flipping.

Output the score for the person and the computer.

Output the opponents whose turn is beginning and ask the user to hit enter to continue.

With each flip of the coins.

Output the result, and amount of the round pot.

If its the users flip ask if they want to Flip again ( F ) or Hold ( H ). Your program should allow r, R, h or H as valid input.

The AI will continue playing until the round pot is 8 or more.

Once a players pot is greater or equal to 20 then they have won, it will no longer ask if they want to keep playing.

Once there is a winner

Score totals are output along with who the winner was. User or Computer

Player is asked if they want to play again Y or N. Valid input should be y, Y, yes, YES, or n, N, no, NO.

When a new game starts the starting flip goes to the player that did not flip last. If the User flipped last in the previous game, then the computer flips first and vice versa.

Development Notes:

You will need a way to flip coins in your program. Python has a module just for random numbers. The module is called random

import random #Make this your first line of code. Allows you to use the random module.

To Get a coin flip you will want a number from 0 to 1 :

coin = random.randint(0, 1)

flip is the variable name. Obviously, you can use whatever name you like.

Strings have two methods that could be useful. .lower() and .upper(). These methods return a string that is lowercased or upper cased respectively.

abcLower = "ABC".lower() # abcLower is "abc"

abcUpper = "abc".upper() # abcUpper is "ABC"

The membership operator in can be useful as well, but is not required.

MY CODE:

import random

your_score = 0 computer_score = 0

print('WELCOME TO GREEDY DICE') print()

def You(): global your_score choice = 'f' pot = 0 print() input('Your turn. Hit enter to continue.') while (choice =='f' or choice =='F'): side = random.randint(0,3) print('COINS : ', end='') if (side == 1): print('TTH ', end='') elif (side == 2): print('THH ', end='') elif (side == 3): print('HHH ', end='') else: print("TTT ", end='') pot = pot + side your_score = your_score + side print('Pot : ',pot, end='') if (your_score >= 20): print() print() print('Congratulations, you won') print() print('SCORE',' ','You :',your_score,' ','AI :',computer_score) break if (side == 0): print(' BUST') print() your_score = your_score - pot break else: choice = input(' (F)lip Again or (H)old?')

def Computer(): global computer_score pot = 0 print() input('It\'s the computer\'s turn. Hit enter to continue.') while (pot < 8): side = random.randint(0,3) print('COINS : ', end='') if (side == 1): print('TTH ', end='') elif (side == 2): print('THH ', end='') elif (side == 3): print('HHH ', end='') else: print('TTT ', end='') pot = pot + side computer_score = computer_score + side if(side == 0): print('Pot : ', pot, end='') else: print('Pot : ', pot) if (computer_score >= 20): print() print('AI won') print() print('SCORE',' ','You :',your_score,' ','AI :',computer_score) break if (side == 0): print(' BUST') print() computer_score = computer_score - pot break def play_again(): user_input = input('Do you want to play Greedy Coin again? (YES/Y/NO/N)') if (user_input.upper() == 'YES' or user_input.upper() =='Y'): return 1; elif (user_input.upper() == 'NO' or user_input.upper() == 'N'): return 0; else: play_again() last_turn = 0 while (1): turn = last_turn while (your_score < 20 and computer_score < 20): print('SCORE',' ','You :',your_score,' ','AI :',computer_score) if (turn == 0): You() turn = 1 else: Computer() turn = 0 if (play_again() == 0): break if (last_turn == 0): last_turn = 1 else: last_turn = 0 print('Good Bye! See you again')

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 Databases Questions!