CSE 101 EXAM 2 QUESTIONS AND VERIFIED
ANSWERS
How to combine the two strings
First_name = 'mickey'
Last_name= 'mouse'
To 'mickey mouse' - answers - full_name= first_name + ' ' + last_name
Full_name
'Mickey mouse'
(the ' ' adds a space so it's not mickeymouse)
Row = 'john smith###mathematics###u3###3.81'
Fields = data.split('###')
Fields - answers - ['john smith', 'mathematics', 'u3', '3.81']
3 ways to access the last three numbers of
Numbers=[7,2,8,2,5,3,10] - answers - numbers[4:]
Numbers[4:len(numbers)]
Numbers[4:7]
For c in 'fruits':
Print(c) - answers - f
R
U
I
T
S
For fruit in ['apple','orange','strawberry','lemon','lime']:
Print(fruit) - answers - apple
Orange
Strawberry
Lemon
Lime
For i in range(-1,6):
Print(i) - answers - -1
0
1
2
3
4
5
, For i in range(1,11,3):
Print(i) - answers - 1
4
7
10
For i in range(0,13,3):
Print(i) - answers - 0
3
6
9
12
For i in range(5,10,2):
Print(i) - answers - 5
7
9
For i in range(5,11,2):
Print(i) - answers - 5
7
9
For i in range(4,10,2):
Print(i) - answers - 4
6
8
For i in range(2,7):
Print(i) - answers - 2
3
4
5
6
Nested loop - answers - a loop inside another loop
Fruit=['apple','orange','strawberry','cherry']
Del fruit[0:1]
Fruit - answers - deletes apple
Fruit=['apple','orange','strawberry','cherry']
Del fruit[0:2]
Fruit - answers - deletes apple and orange
ANSWERS
How to combine the two strings
First_name = 'mickey'
Last_name= 'mouse'
To 'mickey mouse' - answers - full_name= first_name + ' ' + last_name
Full_name
'Mickey mouse'
(the ' ' adds a space so it's not mickeymouse)
Row = 'john smith###mathematics###u3###3.81'
Fields = data.split('###')
Fields - answers - ['john smith', 'mathematics', 'u3', '3.81']
3 ways to access the last three numbers of
Numbers=[7,2,8,2,5,3,10] - answers - numbers[4:]
Numbers[4:len(numbers)]
Numbers[4:7]
For c in 'fruits':
Print(c) - answers - f
R
U
I
T
S
For fruit in ['apple','orange','strawberry','lemon','lime']:
Print(fruit) - answers - apple
Orange
Strawberry
Lemon
Lime
For i in range(-1,6):
Print(i) - answers - -1
0
1
2
3
4
5
, For i in range(1,11,3):
Print(i) - answers - 1
4
7
10
For i in range(0,13,3):
Print(i) - answers - 0
3
6
9
12
For i in range(5,10,2):
Print(i) - answers - 5
7
9
For i in range(5,11,2):
Print(i) - answers - 5
7
9
For i in range(4,10,2):
Print(i) - answers - 4
6
8
For i in range(2,7):
Print(i) - answers - 2
3
4
5
6
Nested loop - answers - a loop inside another loop
Fruit=['apple','orange','strawberry','cherry']
Del fruit[0:1]
Fruit - answers - deletes apple
Fruit=['apple','orange','strawberry','cherry']
Del fruit[0:2]
Fruit - answers - deletes apple and orange