AMAADOR ACADEMYCertificatesVerify a certificate

PYF

Final check — Python Programming Fundamentals: From Zero to Useful Scripts

Answer the 40 questions. You need 80% or more to pass. You can retry as many times as you like.

Study the course →

Question 1What type does the input() function always return?
Question 2Tariq runs n = input('Boxes: '); print(n * 2) and types 5. The screen shows 55 instead of 10. What explains this?
Question 3What do 7 // 2 and 7 % 2 give?
Question 4Sana has price = 4.5 and wants the screen to show Total: 4.50 USD. Which line does exactly that?
Question 5A script sets total = 10 and then prints Total. Python stops with NameError: name 'Total' is not defined. What is the most likely cause?
Question 6Which variable name is valid and follows the PEP 8 style?
Question 7Which numbers does range(2, 6) produce?
Question 8A shop script reads: if total >= 100: d = 0.05 / elif total >= 200: d = 0.10 / else: d = 0. A customer spends 250. Which discount is applied?
Question 9A script asks for a quantity with while True: answer = input('Qty: '), then if answer.isdigit(): break. What does break do here?
Question 10A trainee runs total = 0 / for n in range(1, 4): total += n * 2 / print(total). What is printed?
Question 11A rule says a visitor may enter if they are at least 18 and have an ID card. Which condition expresses it?
Question 12Which value counts as False in an if test?
Question 13What does a function give back if it has no return statement?
Question 14With def greet(name, greeting='Hello'): return f'{greeting}, {name}!' Ali calls greet(greeting='Hi', name='Ali'). What does the call return?
Question 15Lina writes count = 0 and def increase(): count = count + 1. Calling increase() raises UnboundLocalError. What is the cleanest fix?
Question 16Omar defines def add_task(task, tasks=[]): tasks.append(task); return tasks. He calls add_task('a') for Sara and add_task('b') for Hind, and Hind's list shows ['a', 'b']. Why?
Question 17What does assert area(3, 4) == 13 do when area(3, 4) returns 12?
Question 18In def greet(name): ... and the call greet('Sara'), which statement is correct?
Question 19A shop keeps stock levels and must look up the quantity by product name. Which structure fits best?
Question 20With prices = [12, 8, 20, 5], what is prices[1:3]?
Question 21A list holds order numbers [3, 1, 3, 2]. A colleague wants to know how many different order numbers there are. What does len(set([3, 1, 3, 2])) return?
Question 22Hind writes name = ' Sara '; name.strip(); print(name) and still sees the spaces around Sara. Why?
Question 23What does [n for n in range(1, 7) if n % 2 == 0] produce?
Question 24Karim stores coordinates as coords = (33.57, -7.59) and later writes coords[0] = 34. What happens?
Question 25Omar opens report.txt with mode 'w' to add one new line at the end. The next morning the old lines are gone. What should he have used?
Question 26Why should you pass encoding='utf-8' to open() for text files?
Question 27A program asks for a whole number of boxes and a user types 3.5. int('3.5') raises ValueError. Which handling is best?
Question 28A report script reads 5,000 CSV rows and crashes at row 3 because the units value is blank. What is the best design?
Question 29When does the finally block of a try statement run?
Question 30Amal's script reads stock = {'pen': 10} and then stock['lamp']. Which exception does Python raise?
Question 31Which command creates a virtual environment in a folder named .venv?
Question 32Hind's script works on her laptop. A colleague gets ModuleNotFoundError: No module named 'requests'. What prevents this next time?
Question 33Which of these modules is part of the standard library, so it needs no pip install?
Question 34Ali needs the requests package. A forum post tells him to run pip install reqeusts, spelled that way. What should he do?
Question 35What is the purpose of if __name__ == '__main__': at the bottom of a file?
Question 36Hamza reads sales.csv with csv.DictReader and writes print(row['units'] * 2) for a row whose units value is 10. The screen shows 1010. Why?
Question 37Dina's script reads sales.csv and writes its summary into the same sales.csv. What is wrong with this design?
Question 38Nora wants an AI assistant to help with a script that processes the salaries of her company's real employees. What should she paste into the prompt?
Question 39An assistant's script calls csv.read_all(f) and Python raises AttributeError: module 'csv' has no attribute 'read_all'. What is the best next step?
Question 40According to the Python Institute, what is the format of the current PCEP exam (PCEP-30-03)?