Question: python quiz Q1 .Before we can begin to solve problems using computer languages we need to be able to understand them (i.e., we must be
python quiz
Q1 .Before we can begin to solve problems using computer languages we need to be able to understand them (i.e., we must be able to read before we can write!). One way of assessing your ability to comprehend computer language code is to ask you to describe its purpose. What is the purpose of the following Python function definition?
def locate (nums, limit ) :
for postion in range (len (nums) ) :
if nums (postion) >= limit :
return postion
return -1
| It returns the position of the last value in list nums which equals or exceeds limit, or 1 if no value in nums is as big as limit. | ||
| It returns a list of all values in list nums which equal or exceed limit with 1 at the end. | ||
| c | It prints all values in list nums which equal or exceed limit and 1 at the end. | |
| d | It returns the position of the first value in list nums which equals or exceeds limit, or 1 if no value in nums is as big as limit. | |
| e | It returns the positions of all values in list nums which equal or exceed limit, or 1 if no value in nums is as big as limit.
Q2. Suppose there are two non-empty list variables of equal length in Python called coords and sides. The variable coords contains sub-lists of size 2, with each of these values representing an x and a y co-ordinate. The variable sides also contains sub-lists of size 2, with each of these values representing firstly the length then the width of a rectangle. Also assume there is also a function in Python called draw_rectangle which takes as its parameters two integers representing firstly the length then the width of a rectangle. The function then draws that rectangle using Turtle graphics functions. Complete the following code to draw each of the rectangles represented by the length-width pairs in the list sides at the x-y co-ordinates contained at the same index in the list coords. for ( ); Term 1 goto(coords[index])draw_rectangle(sides[index][0], sides[index][1])pair in sidesfor xy in coords:goto(coords[pair])goto(xy)draw_rectangle()draw_rectangle(sides[0][index], sides[1][index])draw_rectangle(sides[0][0], sides[0][1])draw_rectangle(sides[0], sides[1])index in range(len(sides))draw_rectangle(sides[index][index + 1], sides[index][index + 1]): penup( ) Term 2 goto(coords[index]) draw_rectangle(sides[index][0], sides[index][1])pair in sidesfor xy in coords:goto(coords[pair])goto(xy)draw_rectangle()draw_rectangle(sides[0][index], sides[1][index])draw_rectangle(sides[0][0], sides[0][1])draw_rectangle(sides[0], sides[1])index in range(len(sides))draw_rectangle(sides[index][index + 1], sides[index][index + 1]) pendown( ) Term 3 goto(coords[index])draw_rectangle(sides[index][0], sides[index][1])pair in sidesfor xy in coords:goto(coords[pair])goto(xy)draw_rectangle()draw_rectangle(sides[0][index], sides[1][index])draw_rectangle(sides[0][0], sides[0][1])draw_rectangle(sides[0], sides[1])index in range(len(sides))draw_rectangle(sides[index][index + 1], sides[index][index + 1])
|
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
