Quiz 1A (G8) (v1.2) Week3 extra practices PDF

Title Quiz 1A (G8) (v1.2) Week3 extra practices
Course Intro to Programming
Institution Singapore Management University
Pages 2
File Size 148.8 KB
File Type PDF
Total Downloads 87
Total Views 112

Summary

Quiz 1A 15 minutesName10Email IdSectionQ1. [ 6 marks ]What is the output of the following program?You are encouraged to draw the state of computer memory in the blank space on the right to help you work out your answer. The memory state diagram will not be graded though.function definitiondef make_m...


Description

Quiz 1A 15 minutes  Name

Email Id

10

Section Q1. [ 6 marks ] What is the output of the following program? You are encouraged to draw the state of computer memory in the blank space on the right to help you work out your answer. The memory state diagram will not be graded though. # function definition def make_magic(a, b): print(a % 11) print(b // 3) b = a + b if b > 10: print('hello') elif b > 5: print(b) else: print('world') return a # main programs a = 25 b = make_magic(16, 1) print(a) print(b) Output (when executing the code above):

IS111 AY2019-20 T1 (G8)

Draw the memory state diagram here (if you need)

Page 1 of 2

Quiz 1A 15 minutes The code below prompts the user for the unit price of a pen and the amount of money available. It then computes and displays at most how many pens can be bought. A sample run of the code is shown below, where text in italic is user input. What's the unit price? 0.8 How much money do you have? 10 You can buy at most 12 pens.

Some of the code below, however, has some errors. Correct the errors (by canceling the wrong code and write the correct code in the blank space nearby) such that the code can run correctly.

price = input('What's the unit price? ')

amount = input('How much money do you have? ')

num_pens = amount %% price

print('You can buy at most '+num_pens+' pens.')

~~~~ END of QUIZ 1 ~~~~

IS111 AY2019-20 T1 (G8)

Page 2 of 2...


Similar Free PDFs