Module 1: Foundations of Python Programming. After topic 12.
Python final exam
Everything from Topics 1 to 12 in one exam: the language itself, small programs, and a real table of data to clean and analyse.
questions in three parts
34questions in three parts
points
100points
the topics it covers
1 to 12the topics it covers
How the exam works
The three parts of the exam
Part
Questions
Points
What you do
A. Multiple choice
1 to 10
10 x 2 = 20
Choose one answer
B. Coding
11 to 18
8 x 4 = 32
Write a small program
C. Hands-on with data
19 to 34
16 x 3 = 48
Work on a table with pandas
Your answers are saved in this browser while you write. You can close the page and continue later on the same device.
You can run your code as often as you like. While you work, nothing is marked right or wrong.
At the end you press Submit the exam. Every answer is checked, you see your points, and the answer key opens with a sample solution for every question.
After submitting you cannot change your answers.
There is no timer on this page. Your instructor tells you how much time you have.
AMultiple choice
Ten questions, 2 points each. Choose one answer for every question. You can change your choice until you submit.
BCoding
Eight small programs, 4 points each. Every program reads its input with input() and prints one line. The lines that read the input are already written: keep them. The examples show the exact form of the output.
Run tries your code with the input in the box under the editor; change the input to try other cases. When you submit, each program is run with several test inputs that you do not see, and you get the points in proportion to the tests it passes.
11.Ticket price
4 points
A museum sells tickets by age: children under 7 enter free (print 0), ages 7 to 17 pay 5, ages 18 to 64 pay 10, and visitors of 65 and older pay 6. Read an age and print the price.
Examples: the input 30 gives 10the input 6 gives 0
Opening the editor...
Shift + Enter runs
12.Hours and minutes
4 points
Read a number of minutes. Print it as hours and minutes in exactly this form: 2 h 15 min.
Examples: the input 135 gives 2 h 15 minthe input 60 gives 1 h 0 min
Opening the editor...
Shift + Enter runs
13.Sum of the digits
4 points
Read a whole number that is not negative. Print the sum of its digits. Use a loop.
Examples: the input 1234 gives 10the input 7 gives 7
Opening the editor...
Shift + Enter runs
14.Count the vowels
4 points
Read a line of text. Print how many of its letters are vowels (a, e, i, o, u). Capital letters count too.
Examples: the input Data Science gives 5the input Python gives 1
Opening the editor...
Shift + Enter runs
15.Numbers divisible by 3
4 points
Read a whole number n. Print the sum of all numbers from 1 to n that are divisible by 3.
Examples: the input 10 gives 18the input 1 gives 0
Opening the editor...
Shift + Enter runs
16.Above the average
4 points
Read whole numbers written on one line with spaces between them. Print how many of them are greater than their average.
Read words written on one line with spaces between them. Print the word that appears most often, then how many times it appears, on one line. If several words share the highest count, print the one that appears first in the line. Use a dictionary.
Examples: the input red blue red green blue red gives red 3the input one gives one 1
Opening the editor...
Shift + Enter runs
18.Prime or not
4 points
Write a function is_prime(n) that returns True when n is a prime number and False when it is not. A prime number is greater than 1 and can be divided only by 1 and by itself. The last two lines read a number and print the result: keep them.
Examples: the input 17 gives Truethe input 2 gives True
Opening the editor...
Shift + Enter runs
CHands-on with data
Sixteen questions about one data file, 3 points each. The file employees.csv has one row for every employee of a company. It was typed in by hand, so some values are missing and a few rows were entered twice.
The data file of the exam
256 rows and 8 columns. On this page it is already there for your code; download it to work in Jupyter or Colab.
This part works like one notebook. Question 19 reads the file into the table df. Every later question continues from question 19: your answer there is run first, so df is ready and you do not read the file again. A few questions also continue from another question, and they say so. Print exactly what a question asks for, in the order it asks.
19.Import the data
3 points
Import pandas as pd, read the file employees.csv into a table named df, and print its first 5 rows.
Opening the editor...
Shift + Enter runs
20.Size and types
3 points
Print the shape of the table. On the next lines print the data type of every column.
Opening the editor...
Shift + Enter runs
21.The numerical features
3 points
Print the names of the numerical columns as a list.
Opening the editor...
Shift + Enter runs
22.Summary statistics
3 points
Print the summary statistics of the numerical columns (describe), rounded to 2 decimals.
Opening the editor...
Shift + Enter runs
23.Missing values
3 points
Print the number of missing values of every column.
Opening the editor...
Shift + Enter runs
24.Duplicates
3 points
Print the number of duplicated rows. On the next line print the shape the table would have without them. Do not change df.
Opening the editor...
Shift + Enter runs
25.Fill the missing salaries
3 points
The column salary has missing values, and a few salaries are very high. Fill the missing salaries with the mean or with the median: choose the one that the very high salaries do not pull up. Print the value you filled with. On the next line print the number of missing salaries after filling.
Opening the editor...
Shift + Enter runs
26.Fill the missing cities
3 points
The column city is text, so no mean can fill it. Fill its missing values with the most frequent city. Then print the number of employees of every city (value_counts).
Opening the editor...
Shift + Enter runs
27.Fill the missing scores
3 points
Fill the missing values of score with the mean score, rounded to 1 decimal. Print the value you filled with. On the next line print the mean of the column after filling, rounded to 2 decimals.
Opening the editor...
Shift + Enter runs
28.A filter with two conditions
3 points
Print how many employees of the department IT are older than 40.
Opening the editor...
Shift + Enter runs
29.Hired in each year
3 points
Add a column year: the year of the date in hired. Print the number of employees hired in each year, the years in order from the earliest to the latest (value_counts, then sort_index).
Opening the editor...
Shift + Enter runs
30.Mean salary by department
3 points
Calculate the mean salary of every department, rounded to 2 decimals, the highest first. Store the result in by_department and print it.
This question also continues from Question 25: your answer there is run first.
Opening the editor...
Shift + Enter runs
31.The cities
3 points
For every city print the number of employees and their mean age, rounded to 1 decimal: group by city, take the column age, and use agg with count and mean.
This question also continues from Question 26: your answer there is run first.
Opening the editor...
Shift + Enter runs
32.The five best paid
3 points
Print the name, department and salary of the 5 employees with the highest salary, the highest first.
Opening the editor...
Shift + Enter runs
33.Ages as a NumPy array
3 points
Turn the column age into a NumPy array named ages (to_numpy). Print how many employees are older than the mean age. On the next line print the mean age of these employees, rounded to 1 decimal.
Opening the editor...
Shift + Enter runs
34.A chart
3 points
Import matplotlib.pyplot as plt and draw the mean salary of every department (by_department) as a bar chart, with a title and a label for each axis. Nothing has to be printed.
This question also continues from Question 25 and Question 30: your answer there is run first.
Opening the editor...
Shift + Enter runs
Submit the exam
When you submit, every answer is checked, you see your points, and the answer key opens: the right answers of Part A and a sample solution for every question of Parts B and C. After submitting you cannot change your answers.
Part A: Multiple choice
0 of 10 answered
Part B: Coding
0 of 8 answered
Part C: Hands-on with data
0 of 16 answered
Optional. It is written on your result, for example when you save it as a PDF for your instructor. It stays in this browser.