CSCA20H3 Lecture : old stuff.docx
Document Summary
If you want one number a line , then. A=[1,2,3,4,5] sum=0 for single in a: sum+=single print sum. If youw ant all numbers in the same line, then. If youw ant all numbers in the same line, but with a tab in between , then. Note you need to convert the sum ( an integer) into string first !!: one number on a line, is the same as. Print str(sum) +"\n": 3, by defining a function ,and use return, instead of print as the last step, def find_len(x): sum=0 for single in a: sum+=single return sum. Need to be the sam as the for statement ! By using this method, you can return the final result , instead of printing all the results at each step. The comma means this line is not finished yet, the content of the second loop round will be displayed on the same line after the first loop content.