CSC108H5 Lecture 9: BUILT IN FUNCTIONS
CSC108H5 verified notes
9/13View all
Document Summary
Input can come from different sources: keyboard, mouse, clicks, database, a(cid:374)other (cid:272)o(cid:373)puter(cid:859)s storage internet. Keyboard is the most common way to gather input. Python has a input() function for its users. This fu(cid:374)(cid:272)tio(cid:374) has a(cid:374) optio(cid:374)al para(cid:373)eter (cid:272)alled (cid:863)pro(cid:373)pt stri(cid:374)g(cid:863) Once this function is called the prompt string is shown/displayed on screen and the program stops when the user enters a value. Python has an efficient way of handling series of numbers and arithmetic progressions by using the function range() This fu(cid:374)(cid:272)tio(cid:374) is parti(cid:272)ularl(cid:455) useful i(cid:374) (cid:862)loop (cid:863) >>>range(5) range(0,5) the above expression range(5) generates an iterator (repeats) that progresses integers form 0 and ends at 4 (5-1): to show the list of numbers, use command list(range(n)): [0,1,2,3,4: we can exercise more control over the list output by calling the range() function with two arguments: [5,6,7,8: the above example shows an increment of 1.