-1
def magic_n(guess2): #Function, have someone guess if number is 7, max 5 tries
magicn2 == 7
tries = 0
while (tries < 5) and (guess2 != magicn2):
 if guess < 7 :
    tries = tries + 1
    print("Too Low")
    guess2 = int(input("Give me another number since the last one was too high : "))
    elif guess > 7:
    tries = tries + 1
    print("Too high")
    guess2 = int(input("Give me another number since the l ast one was too low : ")
    else :
    print("Good job you got it")

guess2 = int(input("Give me a number please : ") print(magic_n(guess2)

Apologies if this way of asking isn't right, first time using stack overflow

3
  • the indentation ain't right. I guess that's it... Commented Sep 25, 2016 at 13:18
  • stackoverflow.com/questions/7025443/… Commented Sep 25, 2016 at 13:25
  • Indentation is very important in Python. Yours is completely wrong. Please fix that first, so that the question matches your code exactly. Also, make sure you add an additional level of indentation to the whole code block, because that is how SO detects it is code. There is a preview which you can check before submitting. Commented Sep 25, 2016 at 13:42

3 Answers 3

1

The identation isn't right, and you need one more parenthesis before "else".

So it would be:

def magic_n(guess2):
    magicn = 7
    tries = 0
    while (tries < 5) and (guess2 != magicn):
        if guess2 < 7:
            tries += 1
            print("Too Low")
            guess2 = int(input("Give me another number since the last one was too high : "))
        elif guess2 > 7:
            tries += 1
            print("Too high")
            guess2 = int(input("Give me another number since the l ast one was too low : "))
        else:
            print("Good job you got it")
Sign up to request clarification or add additional context in comments.

Comments

1

Yes indentation....

As you are using python...may i suggest you look at PYCHARM as you can avoid errors like this in the future. I use it a lot and it auto formats for you.

https://www.jetbrains.com/pycharm/

Comments

0

line 12 :

guess2 = int(input("Give me another number since the l ast one was too low : ")) //bracket missing

indentation must be proper in python.there isn't } in python so code snippet needs to understand where does my block start and where it ends so

if condition:
   ........
   ........
elif condition :
   ........
   ........
else :
   ........

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.