"Last one loses" counter game help

This is the place for queries that don't fit in any of the other categories.

"Last one loses" counter game help

Postby cramsteems » Wed Nov 20, 2013 6:26 pm

Hi I have been set the the task of:
The game ‘Last one loses’ is played by two players and uses a pile of n counters. Players take turns at removing 1, 2 or 3 counters from the pile. The game continues until there are no counters left and the winner is the one who does not take the last counter.
Using functions, write a program to allow the user to specify n in the range 10 - 50 inclusive. The computer acts as one player, playing at random.

This is the code I have written there seems to be problems with the last if statement can anyone get this working?

Thanks!!!


Code: Select all
import random
number = randowm.randit(10,50)
repeat = 1
while repeat == 1:
    user_guess = int(input("Enter a number between 0 and 4: "))
    number = number - user_guess
    if number > 1:
        print("You have taken the last counter! You Lose!")
        repeat = 0
       
    comp_guess = random.randit(1,3)
    print("The computer has taken {0} conters!".format(comp_guess)
    (number) = number - comp_guess
     if number > 1:
        print("The computer has taken the last counter! You Win!")
        repeat = 0
       
Last edited by Mekire on Wed Nov 20, 2013 11:29 pm, edited 2 times in total.
Reason: Lock.
cramsteems
 
Posts: 10
Joined: Thu Sep 19, 2013 5:11 pm

Re: "Last one loses" counter game help

Postby cramsteems » Wed Nov 20, 2013 6:27 pm

Indents for some reason Haven't shown up.
cramsteems
 
Posts: 10
Joined: Thu Sep 19, 2013 5:11 pm

Re: "Last one loses" counter game help

Postby stranac » Wed Nov 20, 2013 7:04 pm

cramsteems wrote:Indents for some reason Haven't shown up.

You haven't used code tags.
Read this and edit your post: New Users, Read This
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1144
Joined: Thu Feb 07, 2013 3:42 pm

Re: "Last one loses" counter game help

Postby ochichinyezaboombwa » Thu Nov 21, 2013 12:48 am

You have at least three syntax errors (badly indented last "if" is only one of them).
If you run your program, Python tells you what is the problem: read it very thoroughly, fix and try again.
BTW: read this 1st tells you exactly about that in the section "what to include in your post".

Then: you also have a logical problem. Try to find it...
ochichinyezaboombwa
 
Posts: 200
Joined: Tue Jun 04, 2013 7:53 pm

Re: "Last one loses" counter game help

Postby Kebap » Thu Nov 21, 2013 9:52 am

cramsteems wrote:This is the code I have written there seems to be problems with the last if statement can anyone get this working?

Sure I can get this working but I don't think you will learn very much if I just give the solution to you and you don't produce it yourself. Also, I can use interpunction.
Learn: How To Ask Questions The Smart Way
Join the #python-forum IRC channel on irc.freenode.net and chat with uns directly!
Kebap
 
Posts: 396
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe

Re: "Last one loses" counter game help

Postby micseydel » Thu Nov 21, 2013 10:25 am

I think this is a double-post of viewtopic.php?f=6&t=8634&p=11256#p11256
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1355
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA


Return to General Coding Help

Who is online

Users browsing this forum: snippsat and 5 guests