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


热门主题

课程名

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
站长地图