WeThinkCode

WeThinkCode_ IDC Curriculum

Digital Inclusion Program

...

Final Exam

Python Programming Fundamentals

30 questions · Pass mark: 70%

1.What does colors[-1] return?

2.What does this function return when called as double(4)?

def double(n):
    return n * 2

3.What does range(2, 6) produce?

4.Which of these correctly defines a function that adds two numbers?

5.What will this code print?

for item in [1, 2, 3]:
    print(item)

6.What does ' hello '.strip() return?

7.What is the output of this code?

total = 0
for i in range(4):
    total += i
print(total)

8.What does the % operator do in Python?

9.What does sum([10, 20, 30]) return?

10.What does this code produce?

words = "the cat sat".split()
print(len(words))

11.What does this code print?

text = "I love cats"
print(text.replace("cats", "dogs"))

12.What does 'hello'[1] return?

13.How do you access the value for key 'age' in a dictionary called person?

14.What is the correct way to create a string in Python?

15.What does the 'and' operator do?

16.What is the output?

def is_even(n):
    return n % 2 == 0
print(is_even(7))

17.Which keyword immediately stops a loop?

18.What data type is the value True in Python?

19.What does 'banana'.count('a') return?

20.What does a function return if it has no return statement?

21.Which operator joins two strings together?

22.What does this code output?

scores = {"Alice": 90, "Bob": 75}
print(len(scores))

23.Which symbol is used for comments in Python?

24.What does sorted([3, 1, 2]) return?

25.What does len() return when called on a list?

26.What is the output?

x = "5"
print(int(x) * 2)

27.What is the correct syntax for a for loop that runs 5 times?

28.What does 'hello'[::-1] produce?

29.What does str(42) return?

30.What character ends a function definition line?