Go With the Flow


#1

Hello guys,

I have a problem with the first part of conditionals and control flow.
I changed it fo experiment a little bit.

Here is my code, but it does not work properly:

def clinic():
    print "This program will check how good a student you are!"
    answer=raw_input("What mark did you get for coding?")
    if answer >= 7:
        print "You are a very good student!"
    elif answer <= 7 :
        print "You should learn better!"
    else:
        print "You didn't enter a mark! Try again."
        clinic()
clinic()

It will always say that I am a very good student. Why is that????

I Hope someone can help me. Thanks in advance


#2

what you didn't know, is that raw_input gives you a unicode, which we can see if we add a simple print statement:

answer=raw_input("What mark did you get for coding?")
print type(answer)

Now, you actually want to a integer (non decimal number), we can use a simple cast to fix this:

answer=int(raw_input("What mark did you get for coding?"))
print type(answer)

#3

@textmaster59538,

AND
you are calling the clinic() from within
causing an inifinite loop !!!!


#4

But that is if the user enters a invalid mark, so that is a good thing?


#5

Thanks! You Are The Best, man!