繁体   English   中英

在函数中调用参数(Python)

[英]Calling arguments in Function (Python)

我是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.
"""

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))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM