# Introduction to Programming in Python final exam review

Source: https://helio.education/finals/intro-python

[Final exam review](https://helio.education/finals)

# Introduction to Programming in Python final exam review

The topics, worked on a live board with an AI tutor.

[Start my review](https://helio.education/signup?next=%2Fhome%3Fcourse%3Dcs.intro-python)

## Units

1. Values, types and expressions [Values, types and expressions](https://helio.education/subjects/computer-science/intro-python/values-types-expressions) [Variables and assignment](https://helio.education/subjects/computer-science/intro-python/variables-assignment) [Input, output and type conversion](https://helio.education/subjects/computer-science/intro-python/input-output-conversion) Practice What are the value and the type of "4" + "5", and of 4 + 5?Answer '45', a str; and 9, an int Hint: Quotes make text, and plus joins text [Values, types and expressions](https://helio.education/subjects/computer-science/intro-python/values-types-expressions) With a = 6 and b = 2, then a = a * b and b = a - b, what does print(a, b) show?Answer 12 10 Hint: a becomes 12 first, then b is 12 - 2 [Variables and assignment](https://helio.education/subjects/computer-science/intro-python/variables-assignment)
2. Booleans and conditionals What exams ask Every decision a program makes, whether to log a user in, stop a loop or charge a fee, rests on a condition, and a condition with the wrong operator or the wrong grouping gives the wrong answer for just the unusual inputs that tests tend to miss. [Booleans and comparisons](https://helio.education/subjects/computer-science/intro-python/booleans-comparisons) [if, elif and else](https://helio.education/subjects/computer-science/intro-python/if-elif-else) Practice For year = 1600, what do year % 4 == 0, year % 100 == 0 and year % 400 == 0 give?Answer True, True and True Hint: 1600 is 4 times 400 [Booleans and comparisons](https://helio.education/subjects/computer-science/intro-python/booleans-comparisons) What does the program print for score = 79?Answer C Hint: 79 >= 80 is False, 79 >= 70 is True [if, elif and else](https://helio.education/subjects/computer-science/intro-python/if-elif-else)
3. Loops [while loops](https://helio.education/subjects/computer-science/intro-python/while-loops) [for loops and range](https://helio.education/subjects/computer-science/intro-python/for-loops-range) [Loop patterns: accumulate, count, search](https://helio.education/subjects/computer-science/intro-python/loop-patterns) [Nested loops](https://helio.education/subjects/computer-science/intro-python/nested-loops) Practice For n = 2 and count = 0, with while n < 50: n = n * 2 and count = count + 1, what does print(count, n) show?Answer 5 64 Hint: n goes 4, 8, 16, 32, 64 [while loops](https://helio.education/subjects/computer-science/intro-python/while-loops) For k in range(4, 20, 5) with the same block, what is the last value of k?Answer 19 Hint: 4, 9, 14, 19, and 24 is past the stop [for loops and range](https://helio.education/subjects/computer-science/intro-python/for-loops-range)
4. Functions What exams ask Programs beyond a screenful are only manageable as small functions with clear jobs; it is how every project, lab and exam question with "write a program that" is best approached, and testing pieces separately finds bugs where they are, not three calls away. [Defining and calling functions](https://helio.education/subjects/computer-science/intro-python/defining-functions) [Scope and the call stack](https://helio.education/subjects/computer-science/intro-python/scope-call-stack) [Default and keyword arguments and docstrings](https://helio.education/subjects/computer-science/intro-python/default-keyword-arguments) [Designing with functions](https://helio.education/subjects/computer-science/intro-python/decomposition) Practice With def double(n): return n * 2, what does print(double(7) + 1) show?Answer 15 Hint: The call becomes 14 first [Defining and calling functions](https://helio.education/subjects/computer-science/intro-python/defining-functions) With def sq(x): return x * x and def f(a): return sq(a) + 1, how many frames are there at the deepest point of print(f(3)), and what does it print?Answer 3 frames, global, f and sq; it prints 10 Hint: The deepest point is while sq runs [Scope and the call stack](https://helio.education/subjects/computer-science/intro-python/scope-call-stack)
5. Strings What exams ask Text is everywhere in programs, from names and dates to file lines and DNA, and pulling out parts of it by position is the first string skill; the off-by-one at a slice's stop is a classic exam trap, and the same indexing works on lists next unit. Many text tasks have no ready-made method, such as checking a password's rules, cleaning names or validating codes, and the loop over characters with an accumulator is the pattern behind them; reversing and palindromes are classic first exam and interview questions. [String indexing and slicing](https://helio.education/subjects/computer-science/intro-python/indexing-slicing) [String methods and immutability](https://helio.education/subjects/computer-science/intro-python/string-methods) [Processing text with loops](https://helio.education/subjects/computer-science/intro-python/processing-text) Practice name = "Grace". What are name[0], name[-1] and name[2]?Answer G, e and a Hint: G is at 0 [String indexing and slicing](https://helio.education/subjects/computer-science/intro-python/indexing-slicing) s = "Python"; s.lower(); print(s); What is printed, and how do you fix it to print python?Answer Python; write s = s.lower() before the print Hint: Keep the result [String methods and immutability](https://helio.education/subjects/computer-science/intro-python/string-methods)
6. Lists and tuples What exams ask Almost every program keeps a collection of values, test scores, names, readings, and a list is Python's everyday way to hold one; most list bugs are an index one past the end, or a method whose result was used as if it were the list. [Lists: indexing and mutation](https://helio.education/subjects/computer-science/intro-python/lists-basics) [Traversing lists](https://helio.education/subjects/computer-science/intro-python/list-algorithms) [Aliasing and mutability](https://helio.education/subjects/computer-science/intro-python/aliasing-mutability) [Tuples and unpacking](https://helio.education/subjects/computer-science/intro-python/tuples-unpacking) [Nested lists and grids](https://helio.education/subjects/computer-science/intro-python/nested-lists) [List comprehensions](https://helio.education/subjects/computer-science/intro-python/list-comprehensions) Practice For t = [10, 20, 30, 40, 50], what are t[-2] and t[len(t) - 1]?Answer 40 and 50 Hint: -1 is the last, so -2 is the one before it [Lists: indexing and mutation](https://helio.education/subjects/computer-science/intro-python/lists-basics) What does this print: total = 0, for n in [2, 4, 6], total = total + n * n, print(total)?Answer 56 Hint: 4 + 16 + 36 [Traversing lists](https://helio.education/subjects/computer-science/intro-python/list-algorithms)
7. Dictionaries and sets [Dictionaries](https://helio.education/subjects/computer-science/intro-python/dictionaries) [Sets](https://helio.education/subjects/computer-science/intro-python/sets) [Nested data: lists of dictionaries](https://helio.education/subjects/computer-science/intro-python/nested-data) Practice With scores = {"Ana": 8, "Raj": 6}, what is scores["Raj"] + scores.get("Mei", 1)?Answer 7 Hint: "Mei" is not a key, so get gives its default [Dictionaries](https://helio.education/subjects/computer-science/intro-python/dictionaries) What does len(set([4, 4, 7, 7, 7, 2])) give?Answer 3 Hint: The different values are 4, 7 and 2 [Sets](https://helio.education/subjects/computer-science/intro-python/sets)
8. Files and exceptions What exams ask Real programs meet typing mistakes, missing files and impossible values; catching the right exception keeps them running with a helpful message, and raising one makes a function refuse bad input clearly; reading and writing try and except is a standard exam question. CSV is the plain format that spreadsheets, sensors and websites export, and a first real data task is almost always read rows, convert fields, and summarise by group; this read, convert, accumulate pattern is a standard exam and project question. [Reading and writing files](https://helio.education/subjects/computer-science/intro-python/reading-writing-files) [Exceptions](https://helio.education/subjects/computer-science/intro-python/exceptions) [Processing CSV data](https://helio.education/subjects/computer-science/intro-python/csv-data) Practice What are the lines of a file after write("x"), write("y\n") and write("z")?Answer Xy, then z Hint: Only the second write ends a line [Reading and writing files](https://helio.education/subjects/computer-science/intro-python/reading-writing-files) Write safe_float(text) that returns float(text), or 0.0 when the text is not a number.Answer Try: return float(text), except ValueError: return 0.0; safe_float("2.5") gives 2.5 and safe_float("abc") gives 0.0 Hint: Float raises ValueError too [Exceptions](https://helio.education/subjects/computer-science/intro-python/exceptions)
9. Classes and objects What exams ask Real programs share code between kinds of things, such as a savings account that is a bank account with extras, and the questions that matter are which method Python runs for a given object and what breaks when the parent's setup is skipped; both are standard exam traces. [Classes, objects and __init__](https://helio.education/subjects/computer-science/intro-python/classes-init) [Methods, self and __str__](https://helio.education/subjects/computer-science/intro-python/methods-self) [Inheritance](https://helio.education/subjects/computer-science/intro-python/inheritance) Practice After p = BankAccount("Dee", 5) and p.balance = p.balance + 10, what does print(p.owner, p.balance) show?Answer Dee 15 Hint: The attribute is read, then written back [Classes, objects and __init__](https://helio.education/subjects/computer-science/intro-python/classes-init) With c = BankAccount("Cy", 10), then c.deposit(5) and c.deposit(5), what does c.balance show?Answer 20 Hint: Each call reads what the last one stored [Methods, self and __str__](https://helio.education/subjects/computer-science/intro-python/methods-self)
10. Recursion What exams ask Recursion is how many problems are most naturally written, folders inside folders, trees, divide and conquer searches and sorts, and tracing a recursive call on the stack is a standard exam question in a first programming course. Splitting a sequence into its first item and the rest is the pattern behind recursive code on lists, strings, files and trees, and writing reverse, sum or count this way is a standard exam question in a first programming course. [Recursion: base case and recursive case](https://helio.education/subjects/computer-science/intro-python/recursion-basics) [Recursion on strings and lists](https://helio.education/subjects/computer-science/intro-python/recursion-lists-strings) Practice Using factorial, what is factorial(6)?Answer 720, since 6 × 120 Hint: 5! is 120 [Recursion: base case and recursive case](https://helio.education/subjects/computer-science/intro-python/recursion-basics) Trace reverse("dog") and give each returned value.Answer The empty string, "g", "go", "god" Hint: Reverse("og") is "go" [Recursion on strings and lists](https://helio.education/subjects/computer-science/intro-python/recursion-lists-strings)
11. Searching and sorting What exams ask Searching is one of the most common things programs do, and binary search is the first algorithm where a smart idea turns a million steps into twenty; tracing low, mid and high and counting comparisons are standard exam questions. Sorting is everywhere, and these two simple sorts are where students first trace an algorithm pass by pass and count its work; showing the list after each pass and counting comparisons are standard exam questions, and the quadratic count explains why faster sorts exist. [Linear and binary search](https://helio.education/subjects/computer-science/intro-python/linear-binary-search) [Selection sort and insertion sort](https://helio.education/subjects/computer-science/intro-python/selection-insertion-sort) Practice How many comparisons does linear search make for 91, and for 4?Answer 10 and 1 Hint: Where are they in nums? [Linear and binary search](https://helio.education/subjects/computer-science/intro-python/linear-binary-search) Give the list after each pass of selection sort on [5, 1, 4, 2].Answer 1, 5, 4, 2; then 1, 2, 4, 5; then 1, 2, 4, 5 unchanged Hint: The second pass finds 2 [Selection sort and insertion sort](https://helio.education/subjects/computer-science/intro-python/selection-insertion-sort)
12. Testing and debugging What exams ask Code that passes a few happy examples often fails at a boundary or on empty input; writing tests for ordinary, edge and error cases is how programmers catch that before users do, and choosing such cases is a common exam and interview question. Every programmer spends much of their time debugging, and a calm method, read the error, find the line, trace the values, fix one thing and retest, is what separates guessing from fixing; reading a traceback and tracing a loop are standard exam questions. [Testing with assert and test cases](https://helio.education/subjects/computer-science/intro-python/testing-assert) [Debugging](https://helio.education/subjects/computer-science/intro-python/debugging) Practice Write two ordinary tests for a function double(x) that returns 2 * x.Answer For example assert double(3) == 6 and assert double(-4) == -8 Hint: Include a negative number [Testing with assert and test cases](https://helio.education/subjects/computer-science/intro-python/testing-assert) A traceback ends with IndexError, list index out of range, at return xs[3] where xs = [7, 8, 9]. What is wrong?Answer Xs has indexes 0, 1 and 2 only, so xs[3] does not exist Hint: Count from 0 [Debugging](https://helio.education/subjects/computer-science/intro-python/debugging)

[The whole course](https://helio.education/subjects/computer-science/intro-python)

## Questions

### What does the Introduction to Programming in Python review cover?

Every unit of the course, 12 in all. Pick one and Helio teaches it on the board, then asks you questions. Values, types and expressions; Booleans and conditionals; Loops; Functions; Strings; Lists and tuples; Dictionaries and sets; Files and exceptions; Classes and objects; Recursion; Searching and sorting; Testing and debugging.

### Can it help the week before my final?

Yes. Pick a topic, and Helio explains it, checks you and goes over what you miss.

### Is it the same as my class?

It follows the usual topics of Introduction to Programming in Python. For anything else on your syllabus, type the topic and Helio teaches that too.

### How much is free?

30 minutes a month for one learner, with no card. Starter is free for 7 days with a card: cancel in time and pay nothing.

## More courses

- [Introduction to Programming in Java](https://helio.education/finals/intro-programming)
- [Data Structures](https://helio.education/finals/data-structures)
- [Computer Organization](https://helio.education/finals/computer-organization)

[Final exam review](https://helio.education/finals)

## A tutor you can talk to

30 minutes every month. No card.

[Start my review](https://helio.education/signup?next=%2Fhome%3Fcourse%3Dcs.intro-python)

---

# Helio at a glance

> Helio is an AI tutor you talk to, in math, science, English and history. It draws each step on a board and checks the math.

## Key facts

- 187 courses, from first sums to college math.
- What is Helio, and who is it for? An AI tutor you talk to, and it draws each step on a board. It’s for kids in school, college students and adults.
- How is Helio different from a chatbot? You talk, and it draws each step on a board. Course lessons follow a plan made ahead, and every math step is checked.
- How much is free? 30 minutes a month for one learner, with no card. Starter is free for 7 days with a card: cancel in time and pay nothing.
- Which subjects does Helio teach? Math, science, reading and writing, history and computer science. Math goes deepest, and every math step is checked.
- Which language are lessons in? English, Spanish, French, Arabic, Hindi and many more. Pick one in settings, or just speak it.
- What do I need? A phone, tablet or computer with a mic, and a quiet spot.
- How long is a session? Most lessons take 15 to 20 minutes.
- Can my child type instead of talking? Yes. They can type, or choose to write their answers on the board.
- Can Helio help with homework? Yes. Take a photo of up to ten pages, and work through the problems together.
- Does Helio just give the answer? No. It teaches the steps, then hands over the pen.
- Is Helio always right? Not always. Outside math it can be wrong, so ask why.
- Is my child's voice recorded? No. Speech becomes text, and the sound is not saved.
- What can I see as a parent? What your child knows, in plain words, and a replay of each lesson.
- How does my child sign in? With a code and secret words. Children do not need an email.
- Can a whole class use Helio? Yes. Students join a class with a code, and the teacher sees who is stuck.
- Does Helio work with Clever or ClassLink? Not yet. A class code works everywhere, and students need no email.
- The website is in English, Español, Português, Français, Deutsch, Italiano, العربية, עברית, Türkçe, Română, Русский, हिन्दी, 中文, 日本語, 한국어 and Tiếng Việt.
- Helio is made by Surf Platforms Inc. in San Jose, California. Contact: support@helio.education
- To start: make an account at https://helio.education/signup and pick a course or bring homework. Schools start at https://helio.education/schools.

## Plans

- Helio Free: $0. 30 minutes a month, for one learner.
- Helio Starter: $15 a month, or $160 a year. 2 hours a month, for one learner.
- Helio Plus: $50 a month, or $500 a year. 5 hours a month, for one learner.
- Helio Pro: $100 a month, or $1,000 a year. 10 hours a month, shared by up to 3 learners.
- Helio Ultra: $200 a month, or $2,000 a year. 20 hours a month, shared by up to 5 learners.
