首页 > > 详细

讲解 INFO1110 Mock Foundation Test讲解 Python编程

INFO1110 Mock Foundation Test

This is a mock foundation test provided as practice for your Foundation Test attempts which will happen in your allocated workshop during Weeks 8, 10 and 12. There will also be a foundation section on the final exam as a last attempt to achieve an ‘OK ’ or greater on the foundation test.

The questions given here are only an example of what content you will need to understand to pass the test. All of the content that is covered in the Foundation Ed Lessons is examinable in the foundation test.

There is no answer sheet provided for this mock test. Instead, the Week 7 Accelerated Lecture Review will include an explanation of how to answer the questions in the test. This will be recorded and posted on Canvas in the “Recorded Lectures” tab.

Remember that Week 8 is only your first attempt at passing this test. There is no expectation that you will be able to pass it on your first attempt. You should use this as a learning opportunity to identify what you struggled with and what you need to practice.

Good luck!

Multiple Choice Questions (1 mark each)

1. What will the following code print?

print("Hello", end="!")

print("World")

a)  Hello World   b)  Hello!World    c)  Hello! World    d)  Hello World!

2. Which of the following is not a valid variable name in Python?

a)  my_val     b)   info1110     c)  my-data      d)  my variable

3. Which of the following is a valid assignment statement with an appropriate type hint associated?

a)   @vehicle = 'Bike'

b)   max$float = 200.2

c)   weight: float = 3.1

d)   is_valid: bool = "False"

4. What will the following code print?

print("1", "2", "3", sep=", ")

a)   "1", "2", "3"

b)   1, 2, 3

c)   "1" "2" "3"

d)   1, 2, 3

5. What will the following code print?

print("Se" * 2 + "en")

a)  Seeeen

b)  Seenen

c)  Se2en

d)  SeSeen

6. If the missing lines are filled in correctly, the program should subtract up each number in  the list nums from the original total. The total should be printed after the subtractions are completed. For example, if nums is  [3, 7, 2] then the output of the program will be:

Total: 0

1        nums = [3, 7, 2]

2        total = 12

3

4        for num in nums:

5        # ( code WILL go here )

6        # 

Which of the following options is the correct missing code? (New code has been bolded.)

a)  4 for num in nums:

5      total = total - nums[num]

6  print('Total:', total)

b)  4 for num in nums:

5      total = total - num

6  print('Total:', total)

c)  4 for num in nums:

5      total = total - num

6      print('Total:', total)

d)  4  for num in nums:

5      print('Total:', total)

6  total = total - num

7. What will be the output of the program after the following code fragment is executed?

1        words = ['three', 'four', 'five']

2        indices = [3, 2, 1]

3        for word in words:

4            for index in indices:

5                print(word[index], end=' ')

6            print()

a)  h r e o u r i v e

b)  e r h r u o e v i

c)  r h t o u f v i f

d)  t h r f o u f i v

8. Consider the code fragment below. It has a missing piece of code indicated by XXXXX.   You are given a number. The program checks if the number is divisible by either 2 or 3, and prints Divisible by 2 or 3. if it is.

number = 15

if XXXXX:

print("Divisible by 2 or 3.")

else:

print("Not divisible by 2 or 3.")

Which of the following is the correct completion of the if statements?

a)  number % 2 == 0 or number % 3 == 0

b)  number % 2, 3 == 0

c)  number % 2 == 3 or number % 3 == 2

d)  number % 0 == 2 or number % == 3

9. What will be the output of the program after the following code fragment is executed?

1        lowest = 4

2         i = 16 3

4        while i > lowest:

5            print(i, end=' ')

6            i = i // 2 7

8        print(i, end=' ')

a)   16 8 4

b)  16 8 4 2

c)  8 4 2

d)   8 4 2 1

10. What will be the output of the program after the following code fragment is executed?

1    letters = ['U', 'S', 'Y', 'D']

2    for i in range(4):

3        print(letters[3 - i], end=' ')

a)  D Y S U

b)  U S Y

c)  It will print an IndexError

d)  U S Y D

11. If the missing lines are correctly filled in, the program should define a function named clean_message that returns a formatted message with a given item and cost. The main() function will use the clean_message function to get the message and print it. Below is the output of the program:

The Blender costs $59

1    def # ( code WILL go here ) :

2        message = f'The {item} costs ${price}'

3        # ( code MAY go here )

4

5    def main():

6        item = 'Blender'

7        cost = 59

8        msg = clean_message (item, cost)

9        print(msg)

10

11    main()

Which of the following options is the correct missing code?

a)  1     def format_message(item: str, cost: int):

...

3     return message

b)  1     def format_message(item: str, price: int):

...

3     return message

c)  1     def format_message(name: str, cost: int):

...

3.    # no code

d)  1     def format_message(item: str, price: int):

...

3     print(message)

12. A function named format_message has already been defined in the program. The function has the following signature:

format_message(company: str, id: int) -> str:

The program should ask the user for a company name and id, then use

the format_message function to generate the new formatted string from that input.

# format_message defined above

11    def main():

12        company = input('Enter your company: ')

13        id = input('Enter an id: ')

14        # ( code WILL go here )

15        print(message)

16

17    main()

Which of the following options is the correct missing code on line 14?

a)  14    msg = format_message("Company", 100496)

b)  14    msg = format_message(name, int(id))

c)  14    msg = format_message(name, id)

d)  14    format_message(message)


13. What will be the output of the program after the following code fragment is executed? 

1    def func_1(num: int):

2        x = num - 1

3        return x

4

5    def func_2(num: int):

6        y = num * 2

7        return y - 1

8

9    def main():

10        x = 2

11        y = 4

12

13        print(func_1(x), end=' ')

14        print(func_2(y), end=' ')

15        print(x, end=' ')

16        print(y)

17

18    main()

a)  1 7 2 4

b)   1 7 1 7

c)   2 4 2 4

d)  2 4 1 7

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

1    def show_lower (string: str):

2        print(string.lower ()) 3

4    def display_upper (name: str):

5        string = name

6        print(string.upper()) 8

9    def main():

10       string = 'Wow AMAZING'

11       display_upper ('great job')

12       show_lower (string) 13

14   main()

a)  WOW AMAZING

      wow amazing

b)  GREAT JOB

wow amazing

c)  Wow Amazing GREAT JOB

wow amazing

d)  GREAT JOB great job



15. What will be the output of the program after the following code fragment is executed?

1    def check_balance (amount: int):

2        if amount == 20:

3            return 'Time to buy some lunch!'

4        elif amount == 30:

5            return 'When is the Minecraft movie?'

6        elif amount >= 10:

7            return 'Freedom!'

8        else:

9            return 'I am out of ideas.'

10

11    print(check_balance (20))

12    print(check_balance (15))

13    print(check_balance (30))

a)  Time to buy some lunch!

      Freedom!

Freedom!

When is the Minecraft movie

Freedom!

b)  Time to buy some lunch!

Freedom!

When is the Minecraft movie?

c)  Time to buy some lunch!

When is the Minecraft movie?

Freedom!

I am out of ideas.

d)  Freedom!

     Freedom! 

     Freedom!

16. Given the following code snippet:

class Magic:

def __init__ (self, num):

self.num = num

obj = Magic (5)

print(obj.value)

What will be printed?

a) None

b) 10

c) An AttributeError

d) 5


17. You are designing a Vehicle class that should return a descriptive string when printed. The desired output format is:

This vehicle is a "Mazda" made in 2007

Fill in the missing __repr__ () method for the class:

Class Vehicle:

def __init__ (self, make, year):

self.make = make

self.year = year

# Missing __repr__ method

Which of the following implementations correctly defines __repr__ () to meet the specification?

a)  def __repr__ (self, make, year):

return f'This vehicle is a "{self.make}" made in {year}'

b)  def __repr__ (self):

return f'This vehicle is a "{self.make}" made in {year}'

c)  def __str__ (self):

return f'This vehicle is a "{self.make}" made in {year}'

d)  def __repr__ (self):

print(f'This vehicle is a "{self.make}" made in {year}')

18. Given the following implementation of the Movie class:

class Movie:

def __init__ (self, title, year):

self.title = title

self.year = year

def __repr__ (self):

return f"{self.title} was released in {self.year}"

m = Movie("The Big Short", 2015)

print(m)

What will be printed when the code is executed?

a)   The method print() is undefined for the class Movie

b)   The Big Short was released in 2015

c)   Movie(The Big short, 2015)

d)   <main.Movie object at 0x...>

19. Given the following Python class definition:

class Person:

def __init__ (self, name, age):

self.name = name

self.age = age

person1 = Person("Elliot", 21)

person2 = Person (23, "Charlie")

print(person2.age – person2.age)

What will the code print?

a)  2

b)  -2

c)  Charlie.23 – Elliot.21

d)  It will print a TypeError

20. Consider the code:

class Value:

def __init__ (self, x, y):

self.x = x

self.y = y

def __eq__ (self, other):

if isinstance(other, Value):

return self.x == other.x or self.y == other.y

return False

What is the output of:

v1 = Value (1, 2)

v2 = Value (2, 3)

v3 = [1, 3]

print(v1 == v2, v1 == v3)

a)  True True

b)  False False

c)  True False

d)  False True

Code Writing Questions (3 marks each)

21. Complete the following function by copying the function header below and implement code to return only the values that do not contain the given number.

def get_value (values: list, number: int) -> list:

# Implement code to return only the values that contain the given int

Example:

Input:  get_value (['1234', '13579', '2468', '123'], 3)

returns:  ['1234', '13579', '123']

22. Complete the following function by copying the function header increase_nums that

takes a list of digits, and increases every digit in the list by 1. If it reaches 10, it should be a 0 instead.

def increase_nums (number: list) -> list:

# Increase every digit in the list by 1

Example:

Input:  increase_nums ( [4, 7, 9, 3, 1])

returns:   [5, 8, 0, 4, 2]


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

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