gpt4 book ai didi

Python - 需要一个缩进 block

转载 作者:行者123 更新时间:2023-12-03 08:07:16 24 4
gpt4 key购买 nike

关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。












想改进这个问题?将问题更新为 on-topic对于堆栈溢出。

5年前关闭。




Improve this question




只是 Python 的初学者,试图将 GPA 计算器作为一个基本项目,但语法错误:“预期有缩进 block ”

import keyword

classes = int(input("How many classes do you need to calculate?: "))

gpa = 0.0

if classes == 1:

credits = int(input("Please enter the amount of credit hours of the class: "))
grade = input("What was the grade you have earned?: ")

letter_points = letterGradeConversion()

print(letter_points)

elif classes == 2:

credits = int(input("Please enter the amount of credit hours of the first class: "))
grade = input("What was the grade you have earned?: ")

credits = int(input("Please enter the amount of credit hours of the second class: "))
grade = input("What was the grade you have earned?: ")


elif classes == 3:

credits = int(input("Please enter the amount of credit hours of the first class: "))
grade = input("What was the grade you have earned?: ")

credits = int(input("Please enter the amount of credit hours of the second class: "))
grade = input("What was the grade you have earned?: ")

credits = int(input("Please enter the amount of credit hours of the third class: "))
grade = input("What was the grade you have earned?: ")

elif classes == 4:
credits = int(input("Please enter the amount of credit hours of the first class: "))
grade = input("What was the grade you have earned?: ")

credits = int(input("Please enter the amount of credit hours of the second class: "))
grade = input("What was the grade you have earned?: ")

credits = int(input("Please enter the amount of credit hours of the third class: "))
grade = input("What was the grade you have earned?: ")

credits = int(input("Please enter the amount of credit hours of the fourth class: "))
grade = input("What was the grade you have earned?: ")

else:
print("The max number of classes on this application is currently 4")

def letterGradeConversion():
if grade == A:
gpa = gpa + 4
elif grade == B:
gpa = gpa + 3
elif grade == C:
gpa = gpa + 2
elif grade == D:
gpa = gpa + 1
elif grade == F:
gpa = gpa + 0
else:
print("That is not a valid letter grade")

不在代码中:

iuashd;alksdjas;kjdha;slkjaskljsakdljas;ljlkjf;lkjsFLKAJSD;KJASD;KLk;jaS'LKDJ;ldjk;'DH'AHKL'ASJKLASJKQIOWJWQOIH

最佳答案

您的函数定义(def ... : 之后的所有内容)必须缩进。

所以

def letterGradeConversion():
if grade == A:
gpa = gpa + 4
...

代替
def letterGradeConversion():
if grade == A:
gpa = gpa + 4
...

关于Python - 需要一个缩进 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39240657/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com