CSC108H1 Midterm: UTSG CSC 108 20101_t1_solution

26 views3 pages
7 Mar 2019
School
Course
Professor
yifanyang and 39659 others unlocked
CSC108H1 Full Course Notes
21
CSC108H1 Full Course Notes
Verified Note
21 documents

Document Summary

Consider the following (incomplete) function: def in_range(x, y, p): """return true iff x is less than y, and p is in the range x to y inclusive. x, y and p are all floats""". Write the body of this function using an if statement. Solution: if x < y and x <= p and p <= y: return true else: return false. Write the body of this function as a single line of code, without using an if statement. Solution: return x < y and x <= p and p <= y. 15 def one(a): a = a / 2. # what does memory look like now? def two(b): x = 10 + b / 2 return x if __name__ == "__main__": having = 15 print one(having) print having fun = 16 print two(fun) print fun. Draw the state of memory at the moment when the program reaches line 3, as part of the call to function one.

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

Related Documents

Related Questions