forked from aiti-ghana-2012/Lab_Python_02
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex1_answers
More file actions
57 lines (45 loc) · 797 Bytes
/
Copy pathex1_answers
File metadata and controls
57 lines (45 loc) · 797 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
Consider the following code (draw a flowchart diagram if it helps):
if x>2:
if y>2:
z=x+y
print "z is ",z
else:
print "x is ",x
What is the output if:
a.
b.
c.
d.
x = 2 and y = 5? =2
x = 3 and y = 1?= Nothing
x = 1 and y = 1?=1
x = 4 and y = 3?=7
2. Suppose we have the following code:
z = x+3
if z==1:
y=0
elif z==2:
y=10
elif z==4:
y+=1
else:
y=1
a. What is y equal to at after the switch statem
Y=1
b. What if x = 2 and y = 5 at the beginning?
Y=1
3. What does the following code output, and how many times do we run through the loop
body?
i=0
while i < 10:
i+=1
if i%2 == 0:
print i
The output will be 2 4 6 8 10
we will run through the code 10 times
4. How about this version of the code?
while i > 10:
i+=1
if i%2 == 0:
print i
This will give an error because i is not defined