Untitled
unknown
plain_text
3 days ago
2.8 kB
4
Indexable
import random computerShips = [] playerShips = [] computerWater = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] playerWater = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] while len(computerShips) < 3: pick = random.randint(0, 9) if pick not in computerShips: computerShips.append(pick) # Put your solution for creating the player's ships while len(playerShips) < 3: pick = int(input("Where would you like to place your ship at: ")) if pick not in playerShips: playerShips.append(pick) # Resume with the rest of the starter code while len(computerShips) > 0 and len(playerShips) > 0: print("Remaining player ships:", len(playerShips)) print("Remaining computer ships:", len(computerShips)) print("Computer water: ", computerWater) print("Player water: ", playerWater) while True: playerFire = int(input("Pick a target to shoot: ")) if playerFire in computerWater: computerWater[playerFire] = "X" break else: print("Invalid target. Try again") # Put your solution for turning computer shots to X's while computerWater != ["X", "X","X","X","X","X","X","X","X","X"]: print("Computer water: ",computerWater) print("Player water: ", playerWater) while True: playerFire = int(input("\nPick a target to shoot 0-9: ")) if playerFire in computerWater: computerWater[playerFire] = "X" break else: print("Invalid target. Try again") while True: computerFire = random.randint(0,9) if computerFire in playerWater: playerWater[computerFire] = "X" break # Resume with the rest of the starter code print("You shoot at", playerFire) print("The computer shoots at", computerFire) #Put your if/else for whether a player got a hit/miss while len (computerShips) > 0 and len (playerShips) > 0: # Resume with the rest of the starter code computerFire = random.randint(0,9) playerFire = random.choice(0,9) print("The computer shoots at: ", computerFire) print("The player shoots at: ",playerFire) if computerFire in playerShips: print("You've been hit!") playerShips.remove(computerFire) else: print("The computer missed!") if playerFire in computerShips: print("You been hit!") computerShips.remove(playerFire) else: print("The player missed") print("end game") print("\n\n\n") if len(computerShips) == len(playerShips): print("It's a tie!") elif len(playerShips) > len(computerShips): print("You win!") else: print("You lose!")
Editor is loading...
Leave a Comment