Final Review PDF

Summary

This document includes notes and example questions on Python programming topics for a possible examination. The review covers programming topics including: functions, lists, strings, dictionaries, and files. It's a collection of example questions and topics for an education course or program.

Full Transcript

FINAL REVIEW NOTES  Exam must be completed at the Evaluation and Proficiency Center.  A separate appointment is required for each attempt  Testing Windows  First Attempt: Wednesday, November 20th through Tuesday, November 26th  Classes held as normal  In Class Rev...

FINAL REVIEW NOTES  Exam must be completed at the Evaluation and Proficiency Center.  A separate appointment is required for each attempt  Testing Windows  First Attempt: Wednesday, November 20th through Tuesday, November 26th  Classes held as normal  In Class Reviews:  Section 1: Friday Nov 22nd and Monday Nov 25th  Section 3: Monday Nov 25th  Section 5: Tuesday Nov 26th  Second Attempt: Monday December 2nd through Saturday, December 7th  No class sessions  Official Exam Dates:  Section 1: Wednesday, Dec 4th  Section 3: Wednesday, Dec 4th  Section 5: Thursday, Dec 5th NOTES  Materials to take with you  Student ID card  Materials provided by the EPC  A non-graphing calculator  Scratch paper  Pen/Pencil MODULE 6 – FUNCTIONS  Definitions  Calling  Formal and Actual Parameters  Functional Design  Return values vs Return statements vs Termination with Indentation EXAMPLE QUESTION What is the output of the following Python program? def foo(a, b): a=a+b b=a-b print("a =", a, "b =", b) return 42 def main(): a=6 b=7 c=8 b = foo(c+2, 3*a-b) print("a =", a, "b =", b, "c =", c) main() EXAMPLE QUESTION Write a function called is_divisible that takes in two integers, a and b. Return True if either integer is exactly divisible by the other and False otherwise. MODULE 7 – LISTS  Creating a list  Empty Lists  Lists with initial values  Adding new values  +=  append  Accessing values  Indices  Deleting values  remove  del  Pythonic searching EXAMPLE QUESTION What is the output of the following Python code segment? num = [3, 6, 2, 7, 1] for i in range(len(num)-1): num[i] = num[i] + num[i+1] print(num) EXAMPLE QUESTION Write a function called less_than that takes in two parameters: a list called numbers and an integer called target. Traverse the list and determine how many values in the list are strictly less than the target value. Return this count. For example, if numbers contains 3, 8, 7, 7, 4, 1, 6, and 3 and the target value was 7, the function should return 5. EXAMPLE QUESTION What is the output of the following Python code segment? vals = [ ] for i in range(3): row = [ ] for j in range(3): row.append(j * i) vals.append(row) print(vals) MODULE 8 – STRINGS  Creating Strings  Empty Strings  String Variables vs String Literals  Input  String Concatenation  +  *  Indexing  Positive and negative index values  Slicing EXAMPLE QUESTION  Write a function called reverse_sentence that takes in a string called sentence. Print the sentence in reverse to standard out.  For example, if sentence is “The eagle has landed”, reverse_sentence should print “landed has eagle The”.  Hint: existing functions split and reverse may make this process easier. EXAMPLE QUESTION What is the output of the following lines of Python code? name = “Jonathan” print(name[1:5]) MODULE 9 – DICTIONARIES  Creating an empty dictionary  Key:Value pairs  Adding new items  Accessing items  Deleting items EXAMPLE QUESTION Create a dictionary called gardens to store information about different types of home hydroponic gardens. Initialize the dictionary with the following 2 products: “Airgarden” : 319.10 “Farmstand” : 699.50 EXAMPLE QUESTION Write a function called price_lookup, that takes in the garden dictionary and a string representing a model of home hydroponic garden to look up. Determine if the model is in the dictionary. If it is, print the price. If it is not, print that we do not have any information about that model. MODULE 10 – FILES  Open function  File modes  “r”  “w”  File input functions  read  readline  split  File output function  write  Close function EXAMPLE QUESTION  Write a Python program that reads the following file (numbers.txt) and prints the average to a different file (output.txt) 42 65 76 35 82

Use Quizgecko on...
Browser
Browser