Quick python code check Thanks!

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

Quick python code check Thanks!

Postby cramsteems » Wed Nov 20, 2013 8:20 pm

This is the task I have been set:
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.

I think I'm done but there is something wrong with one of the if statements. 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 micseydel on Wed Nov 20, 2013 8:32 pm, edited 1 time in total.
Reason: Locked.
cramsteems
 
Posts: 10
Joined: Thu Sep 19, 2013 5:11 pm

Re: Quick python code check Thanks!

Postby micseydel » Wed Nov 20, 2013 8:34 pm

cramsteems wrote:I think I'm done but there is something wrong with one of the if statements. Thanks!

You should really elaborate more on this. What exactly, in plain English, is happening/not happening which should/shouldn't?

Also, just glancing at your program I can see an indentation error and a missing close paren. Please make sure to never post code with errors like that, unless they're what your question is about.
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: 1390
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Quick python code check Thanks!

Postby cramsteems » Wed Nov 20, 2013 9:02 pm

funnily enough those problems were to do with the problem with the if statement.
Last edited by micseydel on Wed Nov 20, 2013 9:27 pm, edited 1 time in total.
Reason: Locked.
cramsteems
 
Posts: 10
Joined: Thu Sep 19, 2013 5:11 pm


Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot], W3C [Linkcheck] and 4 guests