简体   繁体   English

在函数中调用参数(Python)

[英]Calling arguments in Function (Python)

I am new to python and am just trying to make my first program to compute what someone needs to get on their final to obtain their target grade (similar to rogerhub http://rogerhub.com/final-grade-calculator/ ). 我是python的新手,我只是想制作我的第一个程序来计算某人达到最终成绩才能达到目标成绩所需的条件(类似于rogerhub http://rogerhub.com/final-grade-calculator/ )。 I have a formula that works but cannot seem to call the arguments within the function without running into an error. 我有一个有效的公式,但似乎无法调用函数内的参数而不会遇到错误。 As I said, I just started learning python so I am sure this is just a simple mistake. 就像我说的那样,我刚刚开始学习python,所以我相信这只是一个简单的错误。 Any help would be greatly appreciated. 任何帮助将不胜感激。

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 is a function. class_grade是一个函数。 To make it run, you have to put it's arguments behind it in parentheses: 为了使其运行,您必须在括号后面加上参数:

class_grade(current_grade, target_grade, final_percentage)

The end result: 最终结果:

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