我是python的新手,我只是想让我的第一个程序来计算某人需要获得他们的最终目标等级(类似于rogerhub http://rogerhub.com/final-grade-calculator/)。我有一个有效的公式但似乎无法调用函数内的参数而不会遇到错误。正如我所说,我刚开始学习python,所以我确信这只是一个简单的错误。任何帮助将不胜感激。
current_grade = float(raw_input("Your current grade is:"))
target_grade = float(raw_input("You want at least a :"))
final_percentage = float(raw_input("Your Final is worth:"))
final_percentage = (final_percentage / 100)
semester_percentage = 1 - (final_percentage)
def class_grade(current_grade, target_grade, final_percentage):
grade_needed = ((target_grade - current_grade * (1 - final_percentage))/ final_percentage)
return grade_needed
def main():
pass
if __name__ == '__main__':
main()
class_grade(current_grade, target_grade, final_percentage)
print "In order go get %s your need to get a %s on your final" % (target_grade, class_grade)
""" Formula for program
Insert your known numbers into the following formula:
G= (D-C(1-P))/P
G is the grade you will need on the final test.
C is the grade you're currently carrying in the class.
D stands for what your school has determined as a passing grade. This should be 60 or 70.
P is the percentage of the total grade for which the final test counts.
Both C and D should be whole numbers, while a decimal should be used for P.
"""
答案 0 :(得分:0)
class_grade
是一个功能。要使它运行,你必须在括号中加上它的参数:
class_grade(current_grade, target_grade, final_percentage)
最终结果:
print "In order go get %s your need to get a %s on your final" % (target_grade, class_grade(current_grade, target_grade, final_percentage))