首页 > > 详细

辅导 INFO1110 Introduction to Programming Semester 1 - Mock, 2025辅导 Python语言

INFO1110 Introduction to Programming

Semester 1 - Mock, 2025

MOCK EXAMINATION

Section A: Foundation Knowledge begins here. There are 22 total Questions.

Only complete this section if you do not have OK or above in the Foundation Test

The multiple-choice questions (Q1-Q20) are worth 1 mark each

The coding questions (Q21-Q22) are worth 3 marks each

(1) What will the following code print?

print("X-Y " * 3 + "")

(a) X-Y X-Y X-Y

(b) X-Y X-Y X-Y *

(c) X-Y3*

(d) X-YX-YX-Y*

(2) Consider the code fragment below. Fill in the missing line so the program asks for the user’s age and stores it:

XXX print("Your age is:", age)

(a) age = print("Enter your age: ")

(b) input("Enter your age: ") = age

(c) age = input("Enter your age: ")

(d) print("Enter your age: ") age = int

(3) Which of the following lines will correctly display: "I have 5 apples costing $2.50 each."

count = 5

fruit = "apple"

price = 2.5

print(XXX)

(a) f"I have {count} {fruit}s costing ${price} each."

(b) f"I have {count} {fruit}s costing $2.5 each."

(c) f"I have {count} {fruit}s costing ${price:.2f} each."

(d) "I have " + count + fruit + "s costing $" + price

(4) Which of the following code blocks correctly calculates how many slices of pizza can be bought and how much change remains?

budget = 20.0

slice_price = 3.25

XXX

print(f"Slices: {slices}, Change: ${change:.2f}")

(a) slices = budget % slice_price

change = budget // slice_price

(b) slices = int(budget / slice_price)

change = budget - (slices * slice_price)

(c) slices = budget * slice_price

change = slice_price - budget

(d) slices = slice_price // budget

change = slice_price % budget

(5) What will the following code print?

print("Goodbye" + "Moon", "See" + "You")

(a) GoodbyeMoon SeeYou

(b) Goodbye Moon See You

(c) GoodbyeMoonSeeYou

(d) Goodbye Moon

(6) What is the output of the code below?

nums = [1, 2, 0, 3]

total = 0

for i in nums:

total += nums[i]

print(total, end=' ')

(a) 1 2 3 6

(b) 2 2 2 5

(c) 1 3 3 6

(d) 2 2 3 6

(7) What is the output when running this code with inputs in this order (if required): 1 6 4

attempts = 0

guess = -1

while guess != 4 and attempts < 2:

guess = int(input("Number: "))

attempts += 1

if guess > 4:

print("Too high")

elif guess < 4:

print("Too low")

if guess == 4:

print("Nice!")

(a) Number: 1

Too low

Number: 6

Too high

Number: 4

Nice!

(b) Number: 1

Too low

(c) Number: 1

Too low

Number: 6

Too high

Nice!

(d) Number: 1

Too low

Number: 6

Too high

(8) What is the final output?

value = 100

withdraw = 150

allow_negative = False

if withdraw > value:

if allow_negative:

value -= withdraw

else:

withdraw = value

value = 0

else:

value -= withdraw

print(f"Withdrawn: {withdraw}, Remaining: {value}")

(a) Withdrawn: 100, Remaining: 0

(b) Withdrawn: 150, Remaining: -50

(c) Withdrawn: 150, Remaining: 100

(d) Withdrawn: 50, Remaining: 100

(9) What will be the value of final after running this code?

items = ['a', 'bb', 'ccc', 'd']

final = []

for x in items:

if len(x) > 1:

final.append(x.upper())

else:

final.append('z')

(a) ['z', 'bb', 'ccc', 'z']

(b) ['z', 'BB', 'CCC', 'z']

(c) ['A', 'BB', 'CCC', 'D']

(d) ['a', 'bb', 'ccc', 'd']

(10) What does this program output?

text = 'robot'

while len(text) > 2:

print(text[1])

text = text[1:]

(a) robo

(b) bo

(c) obo

(d) obot

(11) What will be the output of the program after the following code fragment is executed?

def show_info(place):

print(f"Visiting {place.upper()}")

def run():

location = 'Berlin'

show_info('Tokyo')

show_info(location)

run()

(a) Visiting BERLIN

Visiting BERLIN

(b) Visiting TOKYO

Visiting TOKYO

(c) Visiting TOKYO

Visiting BERLIN

(d) Visiting BERLIN

Visiting TOKYO

(12) Complete the code to replace ‘XXXX’ to compute and display the total bill.

def calculate_total(item: str, qty: int) -> float:

return qty * 2.0

def main():

name = input('Item: ')

number = input('Qty: ')

XXXX

print(f'Total: ${bill:.2f}')

main()

(a) bill = calculate_total(int(number))

(b) bill = calculate_total(name, int(number))

(c) bill = calculate_total(int(name), int(number))

(d) bill = calculate_total(number)

(13) What does the following code output when executed?

def describe(temp):

if temp > 30:

return 'Hot'

elif temp < 0:

return 'Cold'

else:

return 'Cool'

print(describe(25))

print(describe(-1))

print(describe(31))

(a) Cool Cold Hot

(b) Hot Cold Cool

(c) Cool Cool Hot

(d) Hot Cool Cold

(14) What will be the output of the program after the following code fragment is executed?

def review(score):

if score <= 50:

return "Fail"

elif score > 90:

return "Outstanding"

else:

return "Pass"

print(review(50))

print(review(90))

print(review(100))

(a) Fail Pass Outstanding

(b) Pass Outstanding Outstanding

(c) Pass Pass Outstanding

(d) Fail Outstanding Outstanding

(15) Fill in the missing lines to define functions start_challenge and complete_challenge.

• start_challenge should display the player’s experience points when starting the challenge.

• complete_challenge should display the player’s experience points after completing the challenge, and then display how much experience they gained.

Challenge 5 started: XP at 250.

Challenge 5 completed: XP at 550.

You earned 300 XP!

1 def # ( code WILL go here ):

2 print(f'Challenge {challenge} started: XP at {xp_start}.')

3

4 def # ( code WILL go here ):

5 gained = xp_end - xp_start

6 print(f'Challenge {challenge} completed: XP at {xp_end}.')

7 print(f'You earned {gained} XP!')

8

9 def main():

10 challenge_id = 5

11 initial_xp = 250

12 start_challenge(challenge_id, initial_xp)

13

14 # Time passes as player completes the challenge...

15 final_xp = 550

16 complete_challenge(challenge_id, initial_xp, final_xp)

17

18 main()

Which of the following options is the correct missing code?

(a) 1 def start_challenge(challenge: int, xp_start: int, xp_end: int):

...

4 def complete_challenge(challenge: int, xp_start: int, xp_end: int):

(b) 1 def start_challenge(challenge: int, xp_start: int):

...

4 def complete_challenge(challenge: int, xp_end: int, xp_start: int):

(c) 1 def start_challenge(challenge: int, xp_start: int):

...

4 def complete_challenge(challenge: int, xp_start: int, xp_end: int):

(d) 1 def start_challenge(challenge: int, xp_start: int, xp_end: int):

...

4 def complete_challenge(challenge: int, xp_start: int):

(16) What is the purpose of the __init__ method in a Python class?

(a) To initiate a loop inside the class.

(b) To create a new object’s state when it is created.

(c) To delete an object when it's no longer needed.

(d) To duplicate an object of the class.

(17) What is the output of this code?

class Dog:

def __init__(self, name):

self.name = name

def adopt(self, new):

self.name = new

def speak(self):

return f"Woof, I am {self.name}!"

buddy = Dog("Buddy")

buddy.adopt("Max")

print(buddy.speak())

(a) Woof, I am new!

(b) Woof, I am Buddy!

(c) Woof, I am Max!

(d) Woof, I am name!

(18) Choose the correct init definition for initializing title (str), pages (int), and genre (str).

class Book:

# Missing method

(a) def __ init __ (self, title, pages, genre):

self = Book(title, pages, genre)

(b) def __init__(title, pages, genre):

title = title

pages = pages

genre = genre

(c) def __init__(self, title, pages, genre):

self.title = title

self.pages = pages

self.genre = genre

(d) def __init__(title, pages, genre):

Book(title)

Book(pages)

Book(genre)

(19) Given the following class definition:

class Bike:

def __init__(self, brand):

self.brand = brand

self.wheels = 2

What is the output after executing:

bike_1 = Bike("Toyota")

bike_2 = Bike("Honda")

bike_1.wheels = 3

print(bike_2.wheels)

(a) 3

(b) 2

(c) An error is raised.

(d) 0

(20) Given the following class definition:

class Athlete:

def __init__(self, height, age):

self.height = height

self.age = age

sprinter = Athlete(200, 21)

swimmer = Athlete(205, 23)

print(swimmer.height - sprinter.age)

What will the code print?

(a) 5

(b) 182

(c) 184

(d) 2

(21) Complete the following function that takes a tuple of integers as input and returns a single string of numbers separated by commas.

Example:

Input: join_numbers((4, 8, 3))

returns: '4,8,3'

def join_numbers(numbers: tuple) -> str:

(22) Complete the function rotate_left that has two parameters, a list and an integer n. It should return a list with every element rotated to the left by n positions. Elements that rotate out of the list should re-enter on the opposite end. You can assume n will not be larger than the length of the list.

Sample input and output:

Input: rotate_left([1,2,3,4], 1)

Returns: [2,3,4,1]





联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!