Python Forum
Assign 1 player to the computer
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Assign 1 player to the computer
#1
Hi all,

Nice to be here :) I'm brand new to python so please be nice!

I have this 'last one loses' game to do. I cannot, for the life of me, get 1 player to be the computer so basically it's me against the computer. The computer choses a number randomly between 1 & 3. It's based on the game of nim. I have it working so both players require human input, but I want it so 1 is human and 1 is the computer. Any idea where i'm going wrong please?

#last one loses game

#import random module
import random

#assign random play to the computer
computer = (random.randint(1,3))

#set player to false
player = False

#set initial state
state = 0
while state < 10 or state > 51:
    state = int(input("Enter counter number between 10 and 50 "))
    
#initial number of counters
print ("The number of counters is ", state)

#get valid move and set player to True
while player == False:
    if state == 1:
        print("The computer has taken 1 counter")
    if state == 2:
        print("The computer taken 2 counters")
    if state == 3:
        print("The computer chosen 3 counters")
        remainingCounters(state)

    print("player ",player)
    while True:
        move=int(input("How many counters would you like to remove? "))
        if move in [1,2,3] and move<state:
            break
        print("Please only choose up to 3 counters!")
    
    #update state
    state=state-move


    #show state
    print("The remaining number of counters is now ", state)


    #check win status - win or lose
    if state == 1:
        print("Player ",player, " wins!")
        break

    #switch players 2->1, 1->2 then go back to valid move line
    ##if player==1:
   ## player=2
   ## else:
      ##  player=1

print("Game over")
Reply


Messages In This Thread
Assign 1 player to the computer - by ironic100 - Aug-14-2020, 10:22 AM
RE: Assign 1 player to the computer - by GOTO10 - Aug-14-2020, 01:51 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  My code won't say Player wins or computer wins. No errors. its_a_meLuigi64 2 1,757 Dec-01-2021, 04:43 PM
Last Post: its_a_meLuigi64

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020