Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How to fix this python code?

hatimmakkihatimmakki CanadaMember Posts: 2
edited September 2015 in Python

Hi everyone,
I am writing a simple python guessing game.
simply, the program asks the user to guess a number, if the number is correct, it shows a message (You win!)... if wrong, it gives the user another chance.
But i have an error.

please check it out, and if you know how to solve it, please let me know.
the code:

gs = 1
first = 1
true = 5
def start(self):
    if first == 1:
        print('welcome')
        g = input('Guess a number:')
        guess = int(g)
        if guess == true:
            print('You win!')
            gs = 0            
        else:
            print('You Lose!!!')
        first = 0
    else:
        g = input("Try again, it's between 0 and 10:")
        guess = int(g)
        if guess == true:
            print('Finally you win!')
            gs = 0            
        else:
            print('Ooooh, you lose again!!!')
        first = 0
while gs == 1:
    start()

The error is

Traceback (most recent call last):
  File "C:\...\GuessGame.py", line 25, in <module>
    start()
TypeError: start() missing 1 required positional argument: 'self'
Tagged:

Comments

  • hatimmakkihatimmakki CanadaMember Posts: 2

    sorry I solved it by changing the code to:

    first = 1
    true = 5
    while True:
        if first == 1:
            print('welcome')
            g = input('Guess a number:')
            guess = int(g)
            if guess == true:
                print('You win!')
                break            
            else:
                print('You Lose!!!')
            first = 0
        else:
            g = input("Try again, it's between 0 and 10:")
            guess = int(g)
            if guess == true:
                print('Finally you win!')
                break           
            else:
                print('Ooooh, you lose again!!!')
            first = 0
    
Sign In or Register to comment.