Python if statement not working correctly

后端 未结 4 1871
有刺的猬
有刺的猬 2021-01-28 01:29

Im a very new Python user (2.7) and have been working my way through the Learn Python The Hard Way course and up to chap 37 and decided to do read through some other learning ma

4条回答
  •  -上瘾入骨i
    2021-01-28 02:09

    In your code, at the if statement you are comparing a str type with a int type. so it is not working as you axpected. Cast the credit as int

    print "How many credits do you currently have: "
    credits = raw_input("> ")
    credits = int(credits)
    if credits >= 120:
       print "You have graduated!"
    else:
       print "Sorry not enough credits"
    

提交回复
热议问题