CSCA20H3 Lecture : old stuff.docx

68 views3 pages
School
Course
Professor

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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents

Related Questions