我想知道为什么我的“ if”语句不起作用。我被要求提供输入,此后什么也没有发生。它不会打印出来是A,B,C还是D。
def main():
printLetterGradeFromNumber(input("The grade as a number: "))
def printLetterGradeFromNumber(number_grade):
A = range(90, 100)
B = range(80, 89)
C = range(70, 79)
D = range(60, 69)
if number_grade == A:
print("That student gets an A")
elif number_grade == B:
print("That student gets a B")
elif number_grade == C:
print("That student gets a C")
elif number_grade == D:
print("That student gets a D")
return number_grade
main()
答案 0 :(得分:4)
if nums.count == 2 {
if nums[slowPointer] == nums[fastPointer] {
nums.remove(at: 1)
}
nums.count
}
中的input
必须转换为main
int
是input
,在str
,True
,{{1} }或A
B
与C
进行比较,因此D
是'90' == 90
in
代替comparison operator, ==
。False
'90' in A
numpy.digitize
False
返回def main():
printLetterGradeFromNumber(int(input("The grade as a number: ")))
def printLetterGradeFromNumber(number_grade):
A = range(90, 100)
B = range(80, 89)
C = range(70, 79)
D = range(60, 69)
if number_grade in A:
print("That student gets an A")
elif number_grade in B:
print("That student gets a B")
elif number_grade in C:
print("That student gets a C")
elif number_grade in D:
print("That student gets a D")
return number_grade
main()
中The grade as a number: 90
That student gets an A
的{{1}}。 digitize
返回index
,而value
返回bins
。value < 60
中的index = 0
找到了字母等级。因此,value >= 90
的顺序必须与index = 4
对应。index
答案 1 :(得分:1)
我希望这就是您要寻找的
def printLetterGradeFromNumber(number_grade):
#A = range(90, 100)
#B = range(80, 89)
#C = range(70, 79)
#D = range(60, 69)
if number_grade >= 90 and number_grade <= 100:
print("That student gets an A")
if number_grade >= 80 and number_grade <= 89:
print("That student gets a B")
elif number_grade >= 70 and number_grade <= 79:
print("That student gets a C")
elif number_grade >= 60 and number_grade <= 69:
print("That student gets a D")
return number_grade
答案 2 :(得分:0)
range(90,100)等于(90,91,92,93,94,95,96,97,98,99)
您需要使用“ in”运算符
if number_grade in A:
print("That student gets an A")
elif number_grade in B:
print("That student gets a B")
elif number_grade in C:
print("That student gets a C")
elif number_grade in D:
print("That student gets a D")
答案 3 :(得分:0)
您无需定义功能。使用“ For”循环。
将成绩设置为A = range(90,101)。 B =范围(80,90),C =范围(70,80),D =范围(60,70)
使用范围时,python会排除上限整数