在單獨的行上打印列表項

[英]Printing list items on separate lines


I am trying to print a list of grades with each grade on its own line and this is what I have so far

我正在嘗試打印每個等級的等級列表,這是我到目前為止所擁有的

grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5]

def print_grades(grades):  

    for grade in grades:  

       print grade  

2 个解决方案

#1


If you try

如果你試試

grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5]

for grade in grades:  

    print grade

it should do what you want. My only concern with the original snippet is that you're not actually calling the function you defined. Instead, try this

它應該做你想要的。我對原始片段的唯一顧慮是你實際上沒有調用你定義的函數。相反,試試這個

grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5]

def print_grades(grades):
    for grade in grades:
        print grade

if __name__ == '__main__':
    print_grades(grades)

#2


Try using this

試試這個

grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5]

def print_grades(grades):  
    for grade in grades:  
       print grade
#main code here 
print_grades(grades) 

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2015/05/06/72fd3dcb71c3476f63ec72879236ce7d.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com