2016-07-22 133 views
-4
def compute_invigilated_mark(): 

    """Prints given name and family name with overall score""" 

    test = 0.15 

    exam = 0.60  

    first_name = input("Given names(s)? ") 

    last_name = input("Family name? ") 

    both_names = last_name.upper() + "," + first_name.title() 

    new_test_percent = float(input("Test percent? ")) * test 

    new_exam_percent = float(input("Exam percent? ")) * exam 

    overall_percent = new_test_percent + new_exam_percent 

    end_result = overall_percent/(exam + test) 

    print(both_names + end_result) 

compute_invigilated_mark() 

我想要得到的最終結果,例如:Bourne, Jason: 66.0告訴我這個功能有什麼問題嗎?

的rrror消息:

builtins.TypeError: Can't convert 'float' object to str implicitly.

注:我昏昏沉沉地出來這樣的,所以你可以閱讀更容易:)。

+1

間距是有幫助的 – Elazar

回答

1

both_names是一個字符串,而end_result是一個浮點數,但是您試圖將它們連接在一起(print(both_names + end_result))。

你應該end_result轉換爲字符串:

print(both_names + str(end_result))

+0

感謝:)最簡單的事情總是趕我出相反的:P –

相關問題