Refer to the Week 9 reading or other resources as necessary to complete this assignment.
In this part, you'll use the the online Python 3 tutor to practice splitting strings into lists.
x = 'I am a string'
z = x.split()
print(z[0])
print(x)
Predict what this code will do and answer Questions 1 and 2 in your writeup.
x = 'I am a string'
for w in x.split():
print(w, end="")
print()
Predict what this code will do and answer Question 3 in your writeup.
x = 'I am a string'
y = x.split()
print(len(y))
Predict what this code will do and answer Question 4 in your writeup.For this part of the lab, you'll use the online Python 3 tutor to build lists using append.
L = [] for i in range(3): L.append(i)Answer Question 5 in your Moodle writeup.
L = [] for j in range(5): L.append(j ** 2)Answer Question 6 in your Moodle writeup.
A = ['Jan.', 'Feb.', 'Mar.', 'Apr.', 'May', 'Jun.', 'Jul.', 'Aug.', 'Sep.', 'Oct.', 'Nov.', 'Dec']
B = []
for month in A:
B.append(month)
Answer Question 7 in your Moodle writeup. Note that there are more efficient ways to do what this code does -- this is just an example that uses append.
import math
def PrintHello():
print("Hello!") # A
def PrintGoodbye():
print("Goodbye!") # B
def HiFive():
print("HiFive!") # C
return 5
def main():
print("Calling PrintHello") # D
PrintHello()
print("Calling HiFive") # E
value1 = HiFive()
print("Result of HiFive:", value1) # F
main()