Q1. (20 points) what is the output of the following program.
x =10
y = 10
def calculate(a, b = 5, c = 3):
global y
x = y % b / a ** c + y / b
y -= x
return y
print x,
calculate(6)
print y
print calculate(3,6)
Q2. (20 points) write a pseudo code, which moves a robot from the left to the right figure.
Input data file Output of the program
Q3. (20 points) write the output of the following code on the world figure on the next to this code.
i) How many times call the function down()? _____________________________________
ii) What is the final position and orientation of the robot? ___________________________
from cs1robots import*
load_world(‘turn.wld')
m=Robot(avenue=2,street=5,
orientation='N',beepers=3)
m.set_trace("red")
def right():
for i in range(3):
m.turn_left()
def down():
for i in range(2):
m.turn_left()
m.move()
def up():
for i in range(2):
right()
m.move()
i=0
while m.carries_beepers():
if m.right_is_clear():
if i%2==0:
up()
else:
m.drop_beeper()
down()
i=i+1
else:
m.move()
Q4A. (10 points) what is the output of the following program.
for i in [1,4,5]:
print i>3 and not 10>i**2 or i%3/2 != 0
Q4B. (10 points) write for loop to produce the following output.
Q5. (20 points) Assume that the following world is “amazing3a.wld”.write a program(python code) that loads
the world, move the robot, and collects all the beepers on its way and drop them at(3,7) as depicted in the
figure on the right below.
Bonus point problem (20 points) Program writing question.
Read number from the keyboard and print “prime” if the number is prime, otherwise print “not prime”.