Py学习  »  pycharm

pycharm中应有类型int的float

interesting Facts • 4 年前 • 638 次点击  
    sub1=int(input("Enter the marks of the first subject: "))
    sub2=int(input("Enter the marks of the second subject: "))
    sub3=int(input("Enter the marks of the third subject: "))
    sub4=int(input("Enter the marks of the fourth subject: "))
    sub5=int(input("Enter the marks of the fifth subject: "))
    avg=(sub1+sub2+sub3+sub4+sub5)/5
    if(avg>=90):
      print("Grade A:")
    elif(avg>=80&avg<90):
      print("Grade B:")
    elif(avg>=70&avg<80):
      print("Grade C:")
    elif(avg>=60&avg<70):
      print("Grade D:")
    else:
      print("Grade F:")
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/38570
 
638 次点击  
文章 [ 1 ]  |  最新文章 4 年前
Simon Byrne
Reply   •   1 楼
Simon Byrne    5 年前

问题是 & 优先级高于比较运算符( >= / < 如此 avg>=80&avg<90 正在被分析为 avg>=(80&avg)<90 . 它正试图这样做 bitwise & 在这两个值之间,但失败了。

你最好把它也写下来

avg>=70 and avg<80

( and 是短路运算符,优先级较低),或

70 <= avg < 80