Duration - 3 hours Student Number: CSC 108H1Y 2013 Final Exam. Aids allowed: none

Size: px
Start display at page:

Download "Duration - 3 hours Student Number: CSC 108H1Y 2013 Final Exam. Aids allowed: none"

Transcription

1 University of Toronto Faculty of Arts and Science August 0 Examinations CSC 08HY 0 Final Exam Duration - hours Student Number: Aids allowed: none Last Name: Lecture Section: L50 First Name: Instructor: Jonathan Lung Do not turn this page until you have received the signal to start. (Please fill out the identification section above, write your name on the back of the test, and read the instructions below.) Reminder: You must achieve at least 40% on this exam in order to pass the course. Good Luck! This exam consists of 8 questions on pages (including this one). When you receive the signal to start, please make sure that your copy is complete. Comments are not required except where indicated, although they may help us mark your answers. They may also get you part marks if you can t figure out how to write the code. No error checking is required: assume all user input and all argument values are valid. If you use any space for rough work, indicate clearly what you want marked. # : # : # : Total Pages =

2

3 E xam Summer 0 Question. [5 m a r k s ] Part (a) [ m a r k ] What is the name of the programming language we used in CSC08 this term? Part ( b ) [ m a r k ] What do we use CamelCase for? Part (c) [ m a r k ] When is the only time variables defined outside a function should be accessed? Part (d) [ m a r k s ] There are at least five things wrong, stylistically, with the following piece of code. Name two of them. There is a p e n a l t y fo r g u e s s i n g. AGE.GAP = if age > : 4 x = AGE_GAP+age 5 # Print x 6 print ( x ) Question. [4 m a r k s ] Part (a) [ m a r k ] The value 0 is has type in t. W hat is the type of 0.0? Part ( b ) [ m a r k ] If s t is the string 'H e llo, why does line one below cause an error but line two below does not? s t [0] = h st = h ' + st[i:] Page of

4 E xam Summer 0 Part (c) [ m a r k ] W hat is the value of var after running all the lines of code directly below? var = 0 var = var var = var Part (d) [ m a r k ] W hat is the value of var after running all the lines of code directly below? var = 0 var = 0 var = var var = var Part ( e ) [ m a r k ] What is printed to the screen by the code below? Assume it is not being run in the shell. def mystery(oooh, scary): oooh = oooh + scary return oooh oooh = 5 myst e r y (oooh, 5) p r i n t (oooh) Part (f) [ m a r k ] What is printed to the screen by the code below? Assume it is not being run in the shell. def myst e r y (): p r i n t ( hello ') return 'csc p r i n t ( 08 ) mystery () 4 P art (g) [ m a r k ] How many parameters does the function below have? def mystery(varl, var, var): magic = varl ** var voodoo = magic + len(var) return magic + voodoo Page of

5 E xam Summer 0 Part (h) [ m a r k s ] Assume the random module has been imported (help for the module is at the end of the exam). Generate a random integer between -00 and 00 (inclusive). Next, print two things to the screen (one on each line): the original random number and the absolute value of the random number Part (i) [ m a r k ] Consider the following function headers and type contracts: def moogah(x, y, z ) : ' ' (int, str, float) -> s t r def f r o o b l e ( x ) : ' ' ' (float) -> float ''> def m a r g h ( x, y ) : " (float, bool) -> b o o l " p = moogah(, 'f, 7.0) q = bazzle(8, f r o o b l e (9.6), p) print(margh(frooble (6), q)) If the following code runs without errors, what is the type contract for bazzle? p = moogah(, f, 7.0) q = bazzle(8, f r o o b l e (9.6), p) print(margh(f r o o b l e (6), q)) Part (j) [4 m a r k s ] Which of the following are statements and which are expressions? In each row, put a checkmark in only one of the two columns to indicate your answer. There is a penalty for guessing. Code Statement Expression < var sib lin g s = b ro th ers + s is t e r s w hile True: i f count < 0: ab s(d istan c e ) re tu rn 5 H e llo Page 4 of

6

7 E xam Summer 0 Question. [5 m a r k s ] Part (a) [ m a r k ] Call the function below so that it returns False. def my_func(varl, var): return varl > 5 or len(var) < 5 Part (b) [ m a r k ] What is the purpose of = and what is the purpose of ==? Part (c) [ m a r k s ] For each of Moogah!, Nerts!, Oops!, Top!, Ruh ro!, and Plz!, give a value of var that will result in the string being printed out. If no value of var will result in that string being printed out, write not possible. if var > 5: p rint( 'Moogah! ) elif var < 5: print( N e r t s! ) if var < 5: p r i n t ( T o p! ) elif var > 0: p r i n t ( O o p s! ) else : p rint( Ruh ro! ) if var < 0: print( Plz! ) String Moogah! N e rts! Oops! Top!' Ruh r o! ' P lz! Value of var Page 5 of

8

9 E xam Summer 0 Question 4. [5 m a r k s ] Part (a) [ m a r k ] Write a block of code that prints out the integers from up to and including 00, one per line. Part ( b ) [ m a r k ] What value(s) does the following function return? def mystery (): for ch in h e l l o : if ch in aeiou : 4 return ch P art (c) [ m a r k ] Write a function named re p e a t that returns the string 'h e llo repeated 00 times ( h e llo h e llo h e llo Do not use string multiplication ( h e llo * 00). Part (d) [ m a r k ] Write a program that prompts the user to enter text from the keyboard until the user types the word ' q u it (without quotes) on a line by itself. Part (e) [ m a r k ] What is the output of the function below? Clearly indicate your answer. flag = False while flag: print("flag") 4 flag = True Page 6 of

10 Question 5. [0 m a r k s ] Part (a) [ m a r k ] Suppose the following code runs without error. What is the type of varl? v a r l ['5 ] = hello' E xam Summer 0 Part (b) [ m a r k ] What is the length of the list [ Mind, th e, gap ]? Your answer should be a number (not a call to a function). Part (c) [ m a r k ] What two indices can be used to access the last item in the list [ Mind, the, gap ]? Part (d) [ m a r k ] What is the length of the list [ [ Apple, Orange ], [ Banana, C at, Dance ]]? Your answer should be a number (not a call to a function). Part (e) [ m a r k ] Suppose st refers to a l i s t. Write a block of code that prints out all the items in st using a while-loop. Part (f) [ m a rk ] Suppose name_to_id refers to a d ie t. Write a block of code that prints out all the values in name_to_id using a for-loop. Page 7 of

11

12 E xam Summer 0 Part (g) [4 m a r k s ] Which of the following will work on c if c is a list but fail if it is a tuple? In each row, put a checkmark in only one of the two columns to indicate your answer. There is a penalty for guessing. Code Works for tuples Fails for tuples p rin t( c [0]) c [0] = 5 C.popO c [ : : - l ] c.re v e rs e () len (c) fo r e in c: p rin t(e ) o If n +o Question 6. [6 m a r k s ] Part (a) [ m a r k ] Write the class definition for a class named Person whose superclass is object. Part (b) [ m a r k s ] Write the entire constructor method (without comments/docstrings) for Person. The constructor should require a name as an argument and assign it to an attribute name. The constructor should also initialize an attribute named age to 0. Part (c) [ m a r k ] Rewrite the constructor above s header such that the name argument is optional and, if unspecified, defaults to the string John Smith. Page 8 of

13

14 Part ( d ) [ m a r k ] E xam Summer 0 Write some code that creates an instance of Person and assigns it to a variable named person Part (e) [ m a rk ] Write a method for Person so that the following behaviour would be achieved for a Person named John Smith: >>> print (person.age) 0 >>> p e r s o n.birthday() Happy birthday, John Smith! >>> print(parson.age) >>> p e r s o n.birthday() Happy birthday, John S m i t h! >>> print(person.age) Page 9 of

15 E xam Summer Q uestion 7. [0 m a r k s ] P a r t (a) [ m a r k s ] Complete the following function according to its docstring. def raise.prices(original_fare_type_to_prices, fare_type_to_increase): ( d i e t of str to float, diet of str to float) -> diet of str to float Modify and return the dictionary original_fare_type_to_prices by adding the corresponding fare difference in fare_type_to_increase. All fare types in fare_type_to_increase exist in original_fare_type_to_prices. >>> raise_prices({ student :.00, adult :.00, senior :.00, c h i l d : 0.75}, { s e n i o r : 0.0, adult': 0.5}) { student :.00, adult :.5, senior :.0, c h i l d : } P a r t (b) [4 m a r k s ] Complete the following function according to its docstring: def is_before(timel, time): ( s t r, str) -> boolean Return True iff the time timel occurs before the time time. Both times are specified as strings of the form hour:minute am/pm. For example, "5: am" and ":0 pm" would be valid times. Days start at midnight (:00 am). >>> is_before(":0 am", ":5 am") True >>> is_before("5:6 pm", "8:09 am") Fa Ise >>> is_before ("5:6 pm", "5:6 pm") False >) ) Page 0 of

16 Part (c) [4 m a r k s ] E xam Summer 0 Complete the following function according to its docstring. Yyou may assume the is_before function works and is in the same file as this function. def earliest_time(times):, (list of str) -> object Return the earliest time in times. >>> earliest_time ( [ : 5 p m, ':0 p m, ' : 5 0 p m ]) ':0 p m >>> earliest_time ([ :56 p m, : 0 8 a m ]) :08 a m >>> earliest_time([]) None > j i Part (d) [5 m a r k s ] Complete the following function according to its docstring. You may assume the is_bef ore and e arlie st_ tim e functions work and are in the same file as this function. def busses_by_route(arrival.times): ( l i s t of [list of strsj) -> d i d of str to list of strs Return a dictionary of route numbers to arrival times for a route in any order. The inner list of arrival_times contains the bus route numbers and the arrival time of the bus. >>> busses_by_route ( [ [ 9 6 Wilson, : 5 p m ], [ 6 5 Weston R d. N o r t h, : 0 p m ], [ 9 6 Wilson, : 5 0 p m ], [ 9 7 Yonge, 4 : 0 0 p m ], [ 6 5 West R d. N o r t h, :58 p m ] ] ) { 9 6 Wilson : [ : 5 p m, : 5 0 p m ], 6 5 Weston R d. N o r t h : [ : 0 p m, : 5 8 p m ], 9 7 Yonge : [ 4 : 0 0 p m ] } > ) > Page of

17 Part (e) [4 m a r k s] E xam Summer 0 Complete the following function according to its docstring. You may assume the is_bef ore, earliest_ tim e, and busses_by_route functions work and are in the same file as this function. def next.bus.by.route(arrival.times): ( l i s t of [list of strsj) -> diet of str to str 4 Return a dictionary of route numbers to next arrival time for a route. 5 The inner list of arrival_times contains route numbers and arrival times. 6 7 >>> busses.by_route ( [ [ 9 6 Wilson, ' : 5 p m ], 8 [ 6 5 Weston R d. North, : 0 p m ], 9 [ 9 6 Wilson, : 5 0 p m ], 0 [ 9 7 Yonge, 4 : 0 0 pm>], [ 6 5 West Rd. No r t h, : 5 8 p m ] ] ) { 9 6 Wilson : : 5 p m, 6 5 Weston R d. N o r t h : : 5 8 p m, Yonge : 4:00 p m } 5 Question 8. [5 m a r k s ] Part (a) [ m a r k s ] Complete the following function according to its docstring. def load(processor.usage, m emory_free, memory.used): ( f l o a t, int, int) -> float 4 Return the computer load given the processor_usage, memory_free, and 5 memory_used. The computer load is the maximum of the processor 6 usage and the percentage of memory used % is represented by the float >>> load (0.95, 8, 8) >>> load (0.0, 8, 8) >>> load (0.0,, 4) Page of

18 E x a m Summer Part (b) [4 m a r k s] In a computer system that needs to be responsive (for example, computers that run websites), a computer that isn t particularly busy (it is idle) should respond to requests. For this question, you may assume the Computer class has a method called loado that requires no arguments when called and that returns the Computer s load. Complete the following function according to its docstring. def first_idle(computers): '''(list of Computers) -> Computer Return the first Computer in computers that is idle. An idle computer is one that has a load of below 0% (0.). Return None if no Computer is idle. > J ) P a r t (c) [4 m a r k s ] Sometimes, no idle computers can be found and the least busy computer should respond instead. You may again assume that the Computer class has a method called loado that requires no arguments when called and that returns the Computer s load. Complete the following function according to its docstring. You may assume that the f ir s t_ id le function above works and is in the same file and that the load doesn t change while this function is executing. def first_responder(computers): ( l i s t of Computers) -> Computer Return the first Computer in from computers that is idle. If no Computer is idle, return any one of the Computers that have the lowest load. An idle computer, is one that has a load of below 0% (0. ). J ) J Page of

19

20 E xam Summer P a r t (d) [5 m a r k s ] In a system that provides high reliability (for example, the space shuttle), there are backup systems that are all performing the same calculations and/or measurements. Sometimes, these disagree. However, to make sure all the computers are in the same state, they need to have any discrepancies fixed. For example, if there are three computers on a space shuttle and two of them decide that the shuttle is going too fast and one disagrees, the one that disagrees should have its vote modified so that its version of events matches the version of events the other systems have agreed upon. Complete the following function according to its docstring. def fix_discrepency(votes, v o t e s, votes): '(list of booleans, list of booleans, list of booleans) -> list of boo leans Each of votesl, votes, and votes is a list of votes (True or False) by a set of computers. If there is a disagreement, modify each of the input lists so that they contain the majority vote and return a copy of the decisions. Each of the input lists will be of the same length. >>> fix_discrepency([true, False, True, False, True], [True, True, True, False, True], [True, False, True, False, False]) [True, False, True, False, True], )> > Page 4 of

21

22 E xam Summer Part (e) [5 m a r k s] Complete the following function according to its docstring. def strong_passwd(passed): """ (str) -> bool A strong password has a length greater than or equal to 6, contains at least one lowercase letter, at least one uppercase letter, and at least one digit. Return True iff passwd is considered strong. >>> strong_passwd( I < c s c l O S ) True UII fl Part (f) [5 m a r k s ] On computer systems such as CDF, passwords are stored in a file named /etc/passw d. Each line in the file looks something like this: username:passw ord:full name:account enabled where account enabled is one of enabled or disabled. None of the usernames, passwords, or full names are permitted to contain colons (:). Complete the following function according to its docstring. For this question, you may assume the strong.passwd function described above works. def disable_bad_accounts(filtered_passwd_file): ( f i l e open for writing) -> None Writes all the accounts in /etc/passwd into filtered_passwd_file, but marking any enabled accounts as disabled if they do not have a strong password. Any previously disabled accounts remain disabled, even if they have strong passwords. The filtered_passwd_file is written to disk before this function returns. ) ) } Page 5 of

23

24 EXAM Summer 0 This space intentionally left blank for extra space for answering questions, rough work, and drawings of turtles. Page 6 of

25 EXAM Summer 0 This space intentionally left blank for extra space for answering questions, rough work, and drawings of top hat-/monocle-wearing pigs. Page 7 of

26 E xam Summer 0 ass str(object) str(object ) -> str st r(bytes_or_buffer[, encoding!!, errors]]) -> str Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of o b j e c t. str () (if defined) or repr ( ob j e ct ). encoding defaults to s y s.g e t defaultencoding(). errors defaults to s t r i c t. Methods defined here: count (...) S.co u n t (sub [, start[, end]]) -> int Return the number of non - overlapping occurrences of substring sub in string S[st a r t :end]. Optional arguments start and end are interpreted as in slice notation. e ndswith(...) S.e n dswith(suffix [, start [, end]]) -> bool Return True if S ends with the specified suffix, False otherwise. With optional start, test S beginning at that position. With optional end, stop comparing S at that position, suffix can also be a tuple of strings to try. f ind (...) S.find(sub[, start[, end]]) -> int Return the lowest index in S where substring sub is found, such that sub is contained within S [ s t a r t :end]. Optional arguments start and end are interpreted as in slice notation. Return - on failure. isalnum (...) S. i s a l n u m O -> bool Return True if all characters in S are alphanumeric and there is at least one character in S, False otherwise. isalpha (...) S. i s a l p h a Q -> bool Return True if all characters in S are alphabetic and there is at least one character in S, False otherwise. isdigit (...) S. i s d i g i t O -> bool Return True if all characters in S are digits and there is at least one character in S, False otherwise. islower (...) S. i s l o w e r O -> bool Return True if all cased characters in S are lowercase and there is at least one cased character in S, False otherwise. isnumeric(...) S.isnumeric() -> bool Return True if there are only numeric characters in S, False otherwise. i sspace(...) S. i s s p a c e O -> bool Return True if all characters in S are whitespace and there is at least one character in S, Page 8 of

27

28 E xam Summer 0 False otherwise. isupper (...) S. i s u p p e r Q -> bool Return True if all cased characters in S arc uppercase and there is at least one cased character in S, False otherwise. j oin (...) S.j o i n (iterable) -> str Return a string which is the concatenation of the strings in the iterable. between elements is S. The separator just (...) S.ljust(width [, fillchar]) -> str Return S left- justified in a Unicode string of length width. Padding is done using the specified fill character (default is a space). lower (...) S.l o w e r () -> str Return a copy of the string S converted to l o w e rcase. lstrip (...) S.l s t r i p ( [chars]) -> str Return a copy of the string S with leading whitespace removed. If chars is given and not None, remove characters in chars instead. part it ion (...) S.partition(sep) -> (head, s e p, tail) Search for the separator sep in S, and return the part before it, the separator itself, and the part after it. If the separator is not found, return S and two empty strings. replace (...) S.rep l a c e ( o l d, new[, count]) -> str Return a copy of S with all occurrences of substring old replaced by new. argument count is given, only the first count occurrences are replaced. If the optional rf ind (...) S.rfi n d (sub [, start [, end]]) -> int Return the highest index in S where substring sub is found, such that sub is contained within S [ s t a r t :end]. Optional arguments start and end are interpreted as in slice notation. Return - on failure. rindex (...) S.r i n d e x (sub [, start [, end]]) -> int Like S. r f i n d O but raise ValueError when the substring is not found. rjust (...) S.rjust(width [, fillchar]) -> str Return S right-justified in a string of length width. Padding is done using the specified fill character (default is a space). rpartit ion (...) S.rpartition(sep) -> (head, sep, tail) Search for the separator sep in S, starting at the end of S, and return the part before it, the separator itself, and the part after it. If the separator is not found, return two empty strings and S. Page 9 of

29

30 E xam Summer 0 rsplit (...) S.r s p l i t (sep = None, maxsplit=-l) -> list of strings Return a list of the words in S, using sep as the delimiter string, starting at the end of the string and working to the front. If maxsplit is given, at most maxsplit splits are done. If sep is not specified, any whitespace string is a separator. rstrip (...) S.r s t r i p ( tchars]) -> str Return a copy of the string S with trailing whitespace removed. If chars is given and not None, remove characters in chars instead. split (...) S.s p l i t (sep = None, maxsplit=-i) -> list of strings Return a list of the words in S, using sep as the delimiter string. If maxsplit is given, at most maxsplit splits are done. If sep is not specified or is None, any whitespace string is a separator and empty strings are removed from the result. splitlines(...) S.s pli t l i n e s ([keepends]) -> list of strings Return a list of the lines in S, breaking at line boundaries. Line breaks are not included in the resulting list unless keepends is given and true. startswith(...) S.startsw i t h ( p r e f i x [, start[, end]]) -> bool Return True if S starts with the specified prefix. False otherwise. With optional start, test S beginning at that position. With optional end, stop comparing S at that position, prefix can also be a tuple of strings to try. strip (...) S.s t r i p ([chars]) -> str Return a copy of the string S with leading and trailing whitespace removed. If chars is given and not None, remove characters in chars instead. s w apcase(...) S. s w a p c a s e Q -> str Return a copy of S with uppercase characters converted to lowercase and vice versa. title (...) S.t i t l e () -> str Return a titlecased version of S, i.e. words start with title case characters, all remaining cased characters have lower case. upper (...) S. u p p e r () -> str Return a copy of S converted to uppercase. zf ill (...) S.zfill(width) -> str Pad a numeric string S with zeros on the left, to fill a field of the specified width. The string S is never truncated. Page 0 of

31

32 E xam Summer 0 class list(object) I l i s t O -> new empty list Il i s t (iterable) -> new list initialized from i terable s items I I Methods defined here: I append (...) L.a ppend(object) -> None -- append object to end I I clear (...) L. c l e a r () -> None -- remove all items from L I I copy (...) L. c o p y O -> list -- a shallow copy of L I I count (...) I L.count(value) -> integer return number of occurrences of value I I extend (...) I L.extend(iterable) -> None -- extend list by appending elements from the iterable I I index (...) I L.i ndex(value, [start, [stop]]) -> integer -- return first index of value. Raises ValueError if the value is not present. I I insert (...) L.i nsert(i n d e x, object) -- insert object before index I I pop (...) I L.p o p ([index]) -> item -- remove and return item at index (default last). I Raises IndexError if list is empty or index is out of r a n g e. I I remove (...) I L.r emove(value) -> None -- remove first occurrence of value. Raises ValueError if the value is not p r e s e n t. I I reverse (...) L. r e v e r s e () -- reverse *IN PLACE* I I sort (...) I L.sort(key=None, reversa=false) -> None -- stable sort *IN PLACE* class diet(object) diet () -> new empty dictionary diet(mapping) -> new dictionary initialized from a mapping o b j e c t s (key, value) pairs d i e t (iterable) -> new dictionary initialized as if via: d = -O for k, v in iterable: d[k] = v diet(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=l, two=) Methods defined here: cl e a r (...) D. c l e a r () -> None. Remove all items from D. copy (...) D. c o p y O -> a shallow copy of D fromkeys (...) diet.fromkeys (S [, v ] ) -> New diet with keys from S and values equal to v. v defaults to None. get (...) D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None, items (...) D. i t e m s O -> a set-like object providing a view on D s items Page of

33 E xam Summer 0 keys (...) D. k e y s Q -> a set-like object providing a view on D s keys pop (...) D.pop(k[,d]) -> v, remove specified key and return the corresponding value. If key is not f o u n d, d is returned if g i v e n, otherwise KeyError is raised popit em (...) D. p o p i t e m O -> (k, v ), remove and return some (key, value) pair as a -tuple; but raise KeyError if D is empty. setdef ault (...) D.s e t d e f a u l t ( k [,d ] ) -> D.get(k,d), also set D[k]=d if k not in D update (...) D.update([E, ]**F) -> None. Update D from diet/ iterable E and F. If E present and has a.keys() method, does: for k in E: D[k] = E[k] If E present and lacks. k e y s O method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k] values (...) D. v a l u e s () -> an object providing a view on D's values Help on module random: NAME random - Random variable g e n e r a t o r s. r a ndint(self, a, b) method of Random instance Return random integer in range [a, b ], including both end points. Page of E nd o f T e st

34

Student Number: Comments are not required except where indicated, although they may help us mark your answers.

Student Number: Comments are not required except where indicated, although they may help us mark your answers. CSC 108H5 F 2018 Midterm Test Duration 90 minutes Aids allowed: none Student Number: utorid: Last Name: First Name: Do not turn this page until you have received the signal to start. (Please fill out the

More information

Student Number: Instructor: Brian Harrington

Student Number: Instructor: Brian Harrington CSC A08 2012 Midterm Test Duration 50 minutes Aids allowed: none Last Name: Student Number: First Name: Instructor: Brian Harrington Do not turn this page until you have received the signal to start. (Please

More information

UTORid: Lecture Section: (circle one): L0101 (MWF10) L0201 (MWF11) Instructor: Jacqueline Smith Jen Campbell

UTORid: Lecture Section: (circle one): L0101 (MWF10) L0201 (MWF11) Instructor: Jacqueline Smith Jen Campbell CSC 108H1 F 2017 Midterm Test Duration 50 minutes Aids allowed: none Last Name: UTORid: First Name: Lecture Section: (circle one): L0101 (MWF10) L0201 (MWF11) Instructor: Jacqueline Smith Jen Campbell

More information

CSC A20H3 S 2011 Test 1 Duration 90 minutes Aids allowed: none. Student Number:

CSC A20H3 S 2011 Test 1 Duration 90 minutes Aids allowed: none. Student Number: CSC A20H3 S 2011 Test 1 Duration 90 minutes Aids allowed: none Last Name: Lecture Section: L0101 Student Number: First Name: Instructor: Bretscher Do not turn this page until you have received the signal

More information

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science DECEMBER 2013 EXAMINATIONS CSC 108 H1F Instructors: Craig and Gries Duration 3 hours PLEASE HAND IN Examination Aids: None Student Number:

More information

Student Number: Comments are not required except where indicated, although they may help us mark your answers.

Student Number: Comments are not required except where indicated, although they may help us mark your answers. CSC 108H5 F 2014 Midterm Test Duration 50 minutes Aids allowed: none Last Name: Student Number: First Name: Lecture Section: L0101 Instructor: Dan Zingaro (9:00-10:00) Lecture Section: L0102 Instructor:

More information

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science SUMMER 2012 EXAMINATIONS CSC 108 H1Y Instructors: Janicki Duration NA PLEASE HAND IN Examination Aids: None Student Number: Family Name(s):

More information

UNIVERSITY OF TORONTO SCARBOROUGH. December 2017 EXAMINATIONS. CSCA20H3 Duration 3 hours. Examination Aids: Instructor: Bretscher

UNIVERSITY OF TORONTO SCARBOROUGH. December 2017 EXAMINATIONS. CSCA20H3 Duration 3 hours. Examination Aids: Instructor: Bretscher PLEASE HAND IN UNIVERSITY OF TORONTO SCARBOROUGH December 2017 EXAMINATIONS CSCA20H3 Duration 3 hours PLEASE HAND IN Examination Aids: None Student Number: Last (Family) Name(s): First (Given) Name(s):

More information

Strings are actually 'objects' Strings

Strings are actually 'objects' Strings Strings are actually 'objects' Strings What is an object?! An object is a concept that we can encapsulate data along with the functions that might need to access or manipulate that data. What is an object?!

More information

Strings. Upsorn Praphamontripong. Note: for reference when we practice loop. We ll discuss Strings in detail after Spring break

Strings. Upsorn Praphamontripong. Note: for reference when we practice loop. We ll discuss Strings in detail after Spring break Note: for reference when we practice loop. We ll discuss Strings in detail after Spring break Strings Upsorn Praphamontripong CS 1111 Introduction to Programming Spring 2018 Strings Sequence of characters

More information

Do not turn this page until you have received the signal to start.

Do not turn this page until you have received the signal to start. CSCA08 Fall 2014 Final Exam Duration 160 minutes Aids allowed: none Student Number: A Instructor: Brian Harrington Last Name: First Name: UtorID (Markus Login): Do not turn this page until you have received

More information

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science APRIL 2012 EXAMINATIONS CSC 108 H1S Instructors: Campbell Duration 3 hours PLEASE HAND IN Examination Aids: None Student Number: Family

More information

CSC148 Fall 2017 Ramp Up Session Reference

CSC148 Fall 2017 Ramp Up Session Reference Short Python function/method descriptions: builtins : input([prompt]) -> str Read a string from standard input. The trailing newline is stripped. The prompt string, if given, is printed without a trailing

More information

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science APRIL 2010 EXAMINATIONS CSC 108 H1S Instructors: Horton Duration 3 hours PLEASE HAND IN Examination Aids: None Student Number: Family Name(s):

More information

String Processing CS 1111 Introduction to Programming Fall 2018

String Processing CS 1111 Introduction to Programming Fall 2018 String Processing CS 1111 Introduction to Programming Fall 2018 [The Coder s Apprentice, 10] 1 Collections Ordered, Dup allow List Range String Tuple Unordered, No Dup Dict collection[index] Access an

More information

COLLEGE OF ENGINEERING, NASHIK-4

COLLEGE OF ENGINEERING, NASHIK-4 Pune Vidyarthi Griha s COLLEGE OF ENGINEERING, NASHIK-4 DEPARTMENT OF COMPUTER ENGINEERING Important PYTHON Questions 1. What is Python? Python is a high-level, interpreted, interactive and object-oriented

More information

Question 1. Part (a) Part (b) December 2013 Final Examination Marking Scheme CSC 108 H1F. [13 marks] [4 marks] Consider this program:

Question 1. Part (a) Part (b) December 2013 Final Examination Marking Scheme CSC 108 H1F. [13 marks] [4 marks] Consider this program: Question 1. Part (a) [4 marks] Consider this program: [13 marks] def square(x): (number) -> number Write what this program prints, one line per box. There are more boxes than you need; leave unused ones

More information

Introduction to String Manipulation

Introduction to String Manipulation Introduction to Computer Programming Introduction to String Manipulation CSCI-UA.0002 What is a String? A String is a data type in the Python programming language A String can be described as a "sequence

More information

UNIVERSITY OF TORONTO SCARBOROUGH. Wnter 2016 EXAMINATIONS. CSC A20H Duration 2 hours 45 mins. No Aids Allowed

UNIVERSITY OF TORONTO SCARBOROUGH. Wnter 2016 EXAMINATIONS. CSC A20H Duration 2 hours 45 mins. No Aids Allowed Student Number: Last Name: First Name: UNIVERSITY OF TORONTO SCARBOROUGH Wnter 2016 EXAMINATIONS CSC A20H Duration 2 hours 45 mins No Aids Allowed Do not turn this page until you have received the signal

More information

Python Tutorial. Day 1

Python Tutorial. Day 1 Python Tutorial Day 1 1 Why Python high level language interpreted and interactive real data structures (structures, objects) object oriented all the way down rich library support 2 The First Program #!/usr/bin/env

More information

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science DECEMBER 2009 EXAMINATIONS CSC 108 H1F Instructors: Gries, Horton, Zingaro Duration 3 hours PLEASE HAND IN Examination Aids: None Student

More information

Do not turn this page until you have received the signal to start.

Do not turn this page until you have received the signal to start. CSCA48 Fall 2015 Final Exam Duration 150 minutes Aids allowed: none Student Number: Instructor: Brian Harrington and Anna Bretscher Last Name: First Name: UtorID (Markus Login): Do not turn this page until

More information

IPSL python tutorial: some exercises for beginners

IPSL python tutorial: some exercises for beginners 1 of 9 10/22/2013 03:55 PM IPSL python tutorial: some exercises for beginners WARNING! WARNING! This is the FULL version of the tutorial (including the solutions) WARNING! Jean-Yves Peterschmitt - LSCE

More information

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines. Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science AUGUST EXAMINATIONS CSC 108H1Y Instructor: Daniel Zingaro Duration three hours PLEASE HAND IN Examination Aids: None. Student Number: Last

More information

Advanced Python. Executive Summary, Session 1

Advanced Python. Executive Summary, Session 1 Advanced Python Executive Summary, Session 1 OBJECT: a unit of data of a particular type with characteristic functionality (i.e., methods and/or use with operators). Everything in Python is an object.

More information

Introductory Linux Course. Python I. Martin Dahlö UPPMAX. Author: Nina Fischer. Dept. for Cell and Molecular Biology, Uppsala University

Introductory Linux Course. Python I. Martin Dahlö UPPMAX. Author: Nina Fischer. Dept. for Cell and Molecular Biology, Uppsala University Introductory Linux Course Martin Dahlö UPPMAX Author: Nina Fischer Dept. for Cell and Molecular Biology, Uppsala University August, 2018 Outline Python basics get started with Python Data types Control

More information

Do not turn this page until you have received the signal to start.

Do not turn this page until you have received the signal to start. CSCA48 Winter 2015 Midterm Exam Duration 100 minutes Aids allowed: none Student Number: Instructors: Anna Bretscher & Brian Harrington Last Name: First Name: UtorID (Markus Login): Please place a checkmark

More information

Chapter 8: More About Strings. COSC 1436, Summer 2018 Dr. Zhang 7/10/2018

Chapter 8: More About Strings. COSC 1436, Summer 2018 Dr. Zhang 7/10/2018 Chapter 8: More About Strings COSC 1436, Summer 2018 Dr. Zhang 7/10/2018 Creating Strings The str Class s1 = str() # Create an empty string s2 = str("welcome") # Create a string Welcome Python provides

More information

Good Luck! CSC207, Fall 2012: Quiz 1 Duration 25 minutes Aids allowed: none. Student Number:

Good Luck! CSC207, Fall 2012: Quiz 1 Duration 25 minutes Aids allowed: none. Student Number: CSC207, Fall 2012: Quiz 1 Duration 25 minutes Aids allowed: none Student Number: Last Name: Lecture Section: L0101 First Name: Instructor: Horton Please fill out the identification section above as well

More information

Do not turn this page until you have received the signal to start.

Do not turn this page until you have received the signal to start. CSCA08 Fall 2015 Term Test #2 Duration 110 minutes Aids allowed: none Last Name: Student Number: Markus Login: First Name: Please place a checkmark ( ) beside your tutorial session Tutorial Number Date/Time

More information

Strings. Chapter 6. Python for Everybody

Strings. Chapter 6. Python for Everybody Strings Chapter 6 Python for Everybody www.py4e.com String Data Type A string is a sequence of characters A string literal uses quotes 'Hello' or "Hello" For strings, + means concatenate When a string

More information

PYTHON MOCK TEST PYTHON MOCK TEST III

PYTHON MOCK TEST PYTHON MOCK TEST III http://www.tutorialspoint.com PYTHON MOCK TEST Copyright tutorialspoint.com This section presents you various set of Mock Tests related to Python. You can download these sample mock tests at your local

More information

Working with Sequences: Section 8.1 and 8.2. Bonita Sharif

Working with Sequences: Section 8.1 and 8.2. Bonita Sharif Chapter 8 Working with Sequences: Strings and Lists Section 8.1 and 8.2 Bonita Sharif 1 Sequences A sequence is an object that consists of multiple data items These items are stored consecutively Examples

More information

Introduction to Python for Plone developers

Introduction to Python for Plone developers Plone Conference, October 15, 2003 Introduction to Python for Plone developers Jim Roepcke Tyrell Software Corporation What we will learn Python language basics Where you can use Python in Plone Examples

More information

Babu Madhav Institute of Information Technology, UTU 2015

Babu Madhav Institute of Information Technology, UTU 2015 Five years Integrated M.Sc.(IT)(Semester 5) Question Bank 060010502:Programming in Python Unit-1:Introduction To Python Q-1 Answer the following Questions in short. 1. Which operator is used for slicing?

More information

The Big Python Guide

The Big Python Guide The Big Python Guide Big Python Guide - Page 1 Contents Input, Output and Variables........ 3 Selection (if...then)......... 4 Iteration (for loops)......... 5 Iteration (while loops)........ 6 String

More information

DECODE SPECIAL OPERATOR, FORMAT OPERATOR CONTENTS TRIPLE QUOTES. IS a-to-z METHODS REPLACE L E N G T H E X P A N D T A B S ENC0D3

DECODE SPECIAL OPERATOR, FORMAT OPERATOR CONTENTS TRIPLE QUOTES. IS a-to-z METHODS REPLACE L E N G T H E X P A N D T A B S ENC0D3 The Game of Strings CONTENTS ACCESS, UPDATE, ESCAPE UNICODE STRINGS MAX MIN TRIPLE QUOTES E X P A N D T A B S ENC0D3 DECODE JUST LSTRIP METHODS IS a-to-z UNIC DE JOIN INDEX SPECIAL OPERATOR, FORMAT OPERATOR

More information

Decisions. Arizona State University 1

Decisions. Arizona State University 1 Decisions CSE100 Principles of Programming with C++, Fall 2018 (based off Chapter 4 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University

More information

Introductory Linux Course. Python I. Pavlin Mitev UPPMAX. Author: Nina Fischer Dept. for Cell and Molecular Biology, Uppsala University

Introductory Linux Course. Python I. Pavlin Mitev UPPMAX. Author: Nina Fischer Dept. for Cell and Molecular Biology, Uppsala University Introductory Linux Course Python I Pavlin Mitev UPPMAX Author: Nina Fischer Dept. for Cell and Molecular Biology, Uppsala University August, 2017 Outline Python introduction Python basics get started with

More information

Python - 2. Jim Eng

Python - 2. Jim Eng Python - 2 Jim Eng jimeng@umich.edu Lists Dictionaries Try... except Methods and Functions Classes and Objects Midterm Review Overview Patterns in programming - 1 Sequential steps Conditional steps Repeated

More information

UNIVERSITY OF TORONTO SCARBOROUGH. Fall 2015 EXAMINATIONS. CSC A20H Duration 3 hours. No Aids Allowed

UNIVERSITY OF TORONTO SCARBOROUGH. Fall 2015 EXAMINATIONS. CSC A20H Duration 3 hours. No Aids Allowed Student Number: Last Name: First Name: UNIVERSITY OF TORONTO SCARBOROUGH Fall 2015 EXAMINATIONS CSC A20H Duration 3 hours No Aids Allowed Do not turn this page until you have received the signal to start.

More information

UNIT-III. All expressions involving relational and logical operators will evaluate to either true or false

UNIT-III. All expressions involving relational and logical operators will evaluate to either true or false UNIT-III BOOLEAN VALUES AND OPERATORS: A boolean expression is an expression that is either true or false. The following examples use the operator ==, which compares two operands and produces if they are

More information

MULTIPLE CHOICE. Chapter Seven

MULTIPLE CHOICE. Chapter Seven Chapter Seven MULTIPLE CHOICE 1. Which of these is associated with a specific file and provides a way for the program to work with that file? a. Filename b. Extension c. File object d. File variable 2.

More information

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science APRIL 2017 EXAMINATIONS CSC 104 H1S Instructor(s): G. Baumgartner Duration 3 hours PLEASE HAND IN No Aids Allowed Student Number: Last (Family)

More information

Introduction to Computer Programming for Non-Majors

Introduction to Computer Programming for Non-Majors Introduction to Computer Programming for Non-Majors CSC 2301, Fall 2016 Chapter 5 Part 1 Instructor: Long Ma The Department of Computer Science Objectives Chapter 5: Sequences: Strings, Lists, and Files

More information

Script language: Python Data structures

Script language: Python Data structures Script language: Python Data structures Cédric Saule Technische Fakultät Universität Bielefeld 3. Februar 2015 Immutable vs. Mutable Previously known types: int and string. Both are Immutable but what

More information

Text Input and Conditionals

Text Input and Conditionals Text Input and Conditionals Text Input Many programs allow the user to enter information, like a username and password. Python makes taking input from the user seamless with a single line of code: input()

More information

CPD for GCSE Computing: Practical Sheet 6 February 14

CPD for GCSE Computing: Practical Sheet 6 February 14 Aims Programming Sheet 6 Arrays in Python Section Aim 1 Arrays A variable with many values Understand the idea of an array as a way to combine many values that are assigned to as single variable. 2 While

More information

Module 3: Strings and Input/Output

Module 3: Strings and Input/Output Module 3: Strings and Input/Output Topics: Strings and their methods Printing to standard output Reading from standard input Readings: ThinkP 8, 10 1 Strings in Python: combining strings in interesting

More information

Variable and Data Type I

Variable and Data Type I Islamic University Of Gaza Faculty of Engineering Computer Engineering Department Lab 2 Variable and Data Type I Eng. Ibraheem Lubbad September 24, 2016 Variable is reserved a location in memory to store

More information

Python. Executive Summary

Python. Executive Summary Python Executive Summary DEFINITIONS OBJECT: a unit of data of a particular type with characteristic functionality (i.e., methods and/or response to operators). Everything in Python is an object. "atomic"

More information

STRINGS. We ve already introduced the string data type a few lectures ago. Strings are subtypes of the sequence data type.

STRINGS. We ve already introduced the string data type a few lectures ago. Strings are subtypes of the sequence data type. HANDOUT 1 Strings STRINGS We ve already introduced the string data type a few lectures ago. Strings are subtypes of the sequence data type. Strings are written with either single or double quotes encasing

More information

UNIVERSITY OF TORONTO Faculty of Arts and Science APRIL 2014 EXAMINATIONS. CSC 108 H1S Instructors: Campbell and Papadopoulou.

UNIVERSITY OF TORONTO Faculty of Arts and Science APRIL 2014 EXAMINATIONS. CSC 108 H1S Instructors: Campbell and Papadopoulou. PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science APRIL 2014 EXAMINATIONS CSC 108 H1S Instructors: Campbell and Papadopoulou Duration 3 hours PLEASE HAND IN Examination Aids: None Student

More information

CS 115 Lecture 8. Selection: the if statement. Neil Moore

CS 115 Lecture 8. Selection: the if statement. Neil Moore CS 115 Lecture 8 Selection: the if statement Neil Moore Department of Computer Science University of Kentucky Lexington, Kentucky 40506 neil@cs.uky.edu 24 September 2015 Selection Sometime we want to execute

More information

UNIVERSITÀ DI PADOVA. < 2014 March >

UNIVERSITÀ DI PADOVA. < 2014 March > UNIVERSITÀ DI PADOVA < 2014 March > Easy-to-learn: Python has relatively few keywords, simple structure, and a clearly defined syntax. Easy-to-read: Python code is much more clearly defined and visible

More information

Do not turn this page until you have received the signal to start. In the meantime, please read the instructions below carefully.

Do not turn this page until you have received the signal to start. In the meantime, please read the instructions below carefully. UNIVERSITY OF TORONTO MISSISSAUGA DECEMBER 2014 FINAL EXAMINATION CSC108H5F Instructor: Zingaro, Petersen, Tong Duration: 3 hours Examination Aids: None Student Number: Family Name(s): Given Name(s): The

More information

UNIVERSITY OF TECHNOLOGY SYDNEY FACULTY OF ENGINEERING AND IT. Let's code with! DOCUMENTATION, MATERIAL, RESOURCES. (version 2)

UNIVERSITY OF TECHNOLOGY SYDNEY FACULTY OF ENGINEERING AND IT. Let's code with! DOCUMENTATION, MATERIAL, RESOURCES. (version 2) UNIVERSITY OF TECHNOLOGY SYDNEY FACULTY OF ENGINEERING AND IT Let's code with! DOCUMENTATION, MATERIAL, RESOURCES (version 2) For UTS FEIT Outreach and UTS Women in Engineering and IT Written by Albert

More information

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D 1/58 Interactive use $ python Python 2.7.5 (default, Mar 9 2014, 22:15:05) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin Type "help", "copyright", "credits" or "license" for more information.

More information

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

Python allows variables to hold string values, just like any other type (Boolean, int, float). So, the following assignment statements are valid:

Python allows variables to hold string values, just like any other type (Boolean, int, float). So, the following assignment statements are valid: 1 STRINGS Objectives: How text data is internally represented as a string Accessing individual characters by a positive or negative index String slices Operations on strings: concatenation, comparison,

More information

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D 1/60 Interactive use $ python Python 2.7.5 (default, Mar 9 2014, 22:15:05) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin Type "help", "copyright", "credits" or "license" for more information.

More information

The second statement selects character number 1 from and assigns it to.

The second statement selects character number 1 from and assigns it to. Chapter 8 Strings 8.1 A string is a sequence A string is a sequence of characters. You can access the characters one at a time with the bracket operator: The second statement selects character number 1

More information

Variable and Data Type I

Variable and Data Type I The Islamic University of Gaza Faculty of Engineering Dept. of Computer Engineering Intro. To Computers (LNGG 1003) Lab 2 Variable and Data Type I Eng. Ibraheem Lubbad February 18, 2017 Variable is reserved

More information

The Irving K. Barber School of Arts and Sciences COSC 111 Final Exam Winter Term II Instructor: Dr. Bowen Hui. Tuesday, April 19, 2016

The Irving K. Barber School of Arts and Sciences COSC 111 Final Exam Winter Term II Instructor: Dr. Bowen Hui. Tuesday, April 19, 2016 First Name (Print): Last Name (Print): Student Number: The Irving K. Barber School of Arts and Sciences COSC 111 Final Exam Winter Term II 2016 Instructor: Dr. Bowen Hui Tuesday, April 19, 2016 Time: 6:00pm

More information

Converting a Lowercase Letter Character to Uppercase (Or Vice Versa)

Converting a Lowercase Letter Character to Uppercase (Or Vice Versa) Looping Forward Through the Characters of a C String A lot of C string algorithms require looping forward through all of the characters of the string. We can use a for loop to do that. The first character

More information

Exceptions and File I/O

Exceptions and File I/O Lab 6 Exceptions and File I/O Lab Objective: In Python, an exception is an error detected during execution. Exceptions are important for regulating program usage and for correctly reporting problems to

More information

Haskell Programs. Haskell Fundamentals. What are Types? Some Very Basic Types. Types are very important in Haskell:

Haskell Programs. Haskell Fundamentals. What are Types? Some Very Basic Types. Types are very important in Haskell: Haskell Programs We re covering material from Chapters 1-2 (and maybe 3) of the textbook. Haskell Fundamentals Prof. Susan Older A Haskell program is a series of comments and definitions. Each comment

More information

Introduction to Python

Introduction to Python Introduction to Python Why is Python? Object-oriented Free (open source) Portable Powerful Mixable Easy to use Easy to learn Running Python Immediate mode Script mode Integrated Development Environment

More information

CS 303E Fall 2011 Exam 2 Solutions and Criteria November 2, Good Luck!

CS 303E Fall 2011 Exam 2 Solutions and Criteria November 2, Good Luck! CS 303E Fall 2011 Exam 2 Solutions and Criteria November 2, 2011 Name: EID: Section Number: Friday discussion time (circle one): 9-10 10-11 11-12 12-1 2-3 Friday discussion TA(circle one): Wei Ashley Answer

More information

6. Data Types and Dynamic Typing (Cont.)

6. Data Types and Dynamic Typing (Cont.) 6. Data Types and Dynamic Typing (Cont.) 6.5 Strings Strings can be delimited by a pair of single quotes ('...'), double quotes ("..."), triple single quotes ('''...'''), or triple double quotes ("""...""").

More information

Introduction to Python

Introduction to Python Introduction to Python خانه ریاضیات اصفهان فرزانه کاظمی زمستان 93 1 Why Python? Python is free. Python easy to lean and use. Reduce time and length of coding. Huge standard library Simple (Python code

More information

CSC 108H1 F 2010 Test 1 Duration 45 minutes Aids allowed: none. Student Number:

CSC 108H1 F 2010 Test 1 Duration 45 minutes Aids allowed: none. Student Number: CSC 108H1 F 2010 Test 1 Duration 45 minutes Aids allowed: none Last Name: Lecture Section: L0101 Student Number: First Name: Instructors: Horton and Engels Do not turn this page until you have received

More information

Part III Appendices 165

Part III Appendices 165 Part III Appendices 165 Appendix A Technical Instructions Learning Outcomes This material will help you learn how to use the software you need to do your work in this course. You won t be tested on it.

More information

UNIVERSITY OF TORONTO Faculty of Arts and Science

UNIVERSITY OF TORONTO Faculty of Arts and Science UNIVERSITY OF TORONTO Faculty of Arts and Science Midterm 2 s CSC148H1F Duration: 50 min. Instructors: Diane Horton, David Liu. Examination Aids: Provided aid sheet Name: Student Number: Please read the

More information

Sequence types. str and bytes are sequence types Sequence types have several operations defined for them. Sequence Types. Python

Sequence types. str and bytes are sequence types Sequence types have several operations defined for them. Sequence Types. Python Python Sequence Types Sequence types str and bytes are sequence types Sequence types have several operations defined for them Indexing Python Sequence Types Each element in a sequence can be extracted

More information

Introduction to Computer Programming for Non-Majors

Introduction to Computer Programming for Non-Majors Introduction to Computer Programming for Non-Majors CSC 2301, Fall 2015 Chapter 5 Part 1 The Department of Computer Science Objectives To understand the string data type and how strings are represented

More information

Python I. Some material adapted from Upenn cmpe391 slides and other sources

Python I. Some material adapted from Upenn cmpe391 slides and other sources Python I Some material adapted from Upenn cmpe391 slides and other sources Overview Names & Assignment Data types Sequences types: Lists, Tuples, and Strings Mutability Understanding Reference Semantics

More information

Overview of List Syntax

Overview of List Syntax Lists and Sequences Overview of List Syntax x = [0, 0, 0, 0] Create list of length 4 with all zeroes x 4300112 x.append(2) 3 in x x[2] = 5 x[0] = 4 k = 3 Append 2 to end of list x (now length 5) Evaluates

More information

There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals:

There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals: Numeric Types There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals: 1-123 +456 2. Long integers, of unlimited

More information

Intro. Scheme Basics. scm> 5 5. scm>

Intro. Scheme Basics. scm> 5 5. scm> Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

More information

Introductory Linux Course. Python I. Nina Fischer Dept. for Cell and Molecular Biology, Uppsala University

Introductory Linux Course. Python I. Nina Fischer Dept. for Cell and Molecular Biology, Uppsala University Introductory Linux Course Python I Nina Fischer Dept. for Cell and Molecular Biology, Uppsala University nina.fischer@icm.uu.se January 12, 2017 Outline q Python introducjon q Python basics get started

More information

Introductory Linux Course. Python I. Nina Fischer Dept. for Cell and Molecular Biology, Uppsala University

Introductory Linux Course. Python I. Nina Fischer Dept. for Cell and Molecular Biology, Uppsala University Introductory Linux Course Python I Nina Fischer Dept. for Cell and Molecular Biology, Uppsala University nina.fischer@icm.uu.se August 26, 2016 Outline q Python introducjon q Python basics get started

More information

CS 1301 Exam 1 Fall 2010

CS 1301 Exam 1 Fall 2010 CS 1301 Exam 1 Fall 2010 Name : Grading TA: Integrity: By taking this exam, you pledge that this is your work and you have neither given nor received inappropriate help during the taking of this exam in

More information

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science AUGUST 2011 EXAMINATIONS CSC 209H1Y Instructor: Daniel Zingaro Duration three hours PLEASE HAND IN Examination Aids: one two-sided 8.5x11

More information

Types, lists & functions

Types, lists & functions Week 2 Types, lists & functions Data types If you want to write a program that allows the user to input something, you can use the command input: name = input (" What is your name? ") print (" Hello "+

More information

Topic 7: Lists, Dictionaries and Strings

Topic 7: Lists, Dictionaries and Strings Topic 7: Lists, Dictionaries and Strings The human animal differs from the lesser primates in his passion for lists of Ten Best H. Allen Smith 1 Textbook Strongly Recommended Exercises The Python Workbook:

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

Strings, Lists, and Sequences

Strings, Lists, and Sequences Strings, Lists, and Sequences It turns out that strings are really a special kind of sequence, so these operations also apply to sequences! >>> [1,2] + [3,4] [1, 2, 3, 4] >>> [1,2]*3 [1, 2, 1, 2, 1, 2]

More information

CPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points)

CPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points) Name Definition Matching (8 Points) 1. (8 pts) Match the words with their definitions. Choose the best definition for each word. Relational Expression Iteration Counter Count-controlled loop Loop Flow

More information

Key Differences Between Python and Java

Key Differences Between Python and Java Python Python supports many (but not all) aspects of object-oriented programming; but it is possible to write a Python program without making any use of OO concepts. Python is designed to be used interpretively.

More information

CS 115 Lecture 13. Strings. Neil Moore. Department of Computer Science University of Kentucky Lexington, Kentucky

CS 115 Lecture 13. Strings. Neil Moore. Department of Computer Science University of Kentucky Lexington, Kentucky CS 115 Lecture 13 Strings Neil Moore Department of Computer Science University of Kentucky Lexington, Kentucky 40506 neil@cs.uky.edu 29 October 2015 Strings We ve been using strings for a while. What can

More information

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved. Assoc. Prof. Marenglen Biba (C) 2010 Pearson Education, Inc. All This chapter discusses class String, from the java.lang package. These classes provide the foundation for string and character manipulation

More information

CIS192: Python Programming Data Types & Comprehensions Harry Smith University of Pennsylvania September 6, 2017 Harry Smith (University of Pennsylvani

CIS192: Python Programming Data Types & Comprehensions Harry Smith University of Pennsylvania September 6, 2017 Harry Smith (University of Pennsylvani CIS192: Python Programming Data Types & Comprehensions Harry Smith University of Pennsylvania September 6, 2017 Harry Smith (University of Pennsylvania) CIS 192 Fall Lecture 2 September 6, 2017 1 / 34

More information

CS 115 Lecture 4. More Python; testing software. Neil Moore

CS 115 Lecture 4. More Python; testing software. Neil Moore CS 115 Lecture 4 More Python; testing software Neil Moore Department of Computer Science University of Kentucky Lexington, Kentucky 40506 neil@cs.uky.edu 8 September 2015 Syntax: Statements A statement

More information

Worksheet 6: Basic Methods Methods The Format Method Formatting Floats Formatting Different Types Formatting Keywords

Worksheet 6: Basic Methods Methods The Format Method Formatting Floats Formatting Different Types Formatting Keywords Worksheet 1: Introductory Exercises Turtle Programming Calculations The Print Function Comments Syntax Semantics Strings Concatenation Quotation Marks Types Variables Restrictions on Variable Names Long

More information

******************** YOUR UCINET ID TIME MWF AT: 8A P ****** K E Y ****** TA S NAME ******************** Second Midterm

******************** YOUR UCINET ID TIME MWF AT: 8A P ****** K E Y ****** TA S NAME ******************** Second Midterm ICS 31 UC IRVINE FALL 2014 DAVID G. KAY YOUR NAME YOUR LAB: YOUR STUDENT ID (8 DIGITS) SECTION (1-16) ******************** YOUR UCINET ID TIME MWF AT: 8A 10 12 2 4 6 8P ****** K E Y ****** TA S NAME ********************

More information

CSC 108H1 F 2009 Test 1 Duration 35 minutes Aids allowed: none. Student Number:

CSC 108H1 F 2009 Test 1 Duration 35 minutes Aids allowed: none. Student Number: CSC 108H1 F 2009 Test 1 Duration 35 minutes Aids allowed: none Last Name: Student Number: First Name: Lecture Section: L0102 Instructor: Gries Do not turn this page until you have received the signal to

More information

Handling Strings and Bytes

Handling Strings and Bytes Chapter 9 Handling Strings and Bytes In this chapter, we present some of the most used methods in strings and bytes objects. Strings are extremely useful to manage most of the output generated from programs,

More information

Question 1. December 2009 Final Examination Marking Scheme CSC 108 H1F

Question 1. December 2009 Final Examination Marking Scheme CSC 108 H1F Question 1. [10 marks] Below are five segments of code. Each one runs without error. To the right of each segment, show the output it generates. L = [1, 2, 3, 4] for item in L: item = item * 5 print L

More information