代写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]





热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图