簡體   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