Python for everybody Week 8 Quiz Answer
Hello Friends in this article i am gone to share Coursera Course: Python Data Structures Week 8 Quiz Answers with you..
How are “collection” variables different from normal variables?
- Collection variables can only store a single value
- Collection variables can store multiple values in a single variable
- Collection variables merge streams of output into a single stream
- Collection variables pull multiple network documents together
What are the Python keywords used to construct a loop to iterate through a list?
- for / in
- try / except
- def / return
- foreach / in
For the following list, how would you print out ‘Sally’?
friends = [ 'Joseph', 'Glenn', 'Sally' ]
- print friends
- print friends
- print friends[2:1]
- print friends[‘Sally’]
What would the following Python code print out?
fruit = 'Banana' fruit = 'b' print fruit
- Nothing would print – the program fails with a traceback
Which of the following Python statements would print out the length of a list stored in the variable data?
- print data.length
- print strlen(data)
- print length(data)
- print data.length()
- print len(data)
- print data.Len
What type of data is produced when you call the range() function?
x = range(5) A boolean (true/false) value
- A list of integers
- A list of words
- A string
- A list of characters
What does the following Python code print out?
a = [1, 2, 3] b = [4, 5, 6] c = a + b print len(c)
- [1, 2, 3]
- [4, 5, 6]
- [1, 2, 3, 4, 5, 6]
Which of the following slicing operations will produce the list [12, 3]?
t = [9, 41, 12, 3, 74, 15]
What list method adds a new item to the end of an existing list?
What will the following Python code print out?
friends = [ 'Joseph', 'Glenn', 'Sally' ] friends.sort() print friends
Week 8 Assignment 1
fname = input("Enter file name: ") fh = open(fname) data= for each in fh: words=each.split() for word in words: if word not in data: data.append(word) print(sorted(data))
Week 8 Assignment 2
fname = input("Enter file name: ") if len(fname) < 1 : fname = "mbox-short.txt" #opening the file fh = open(fname) count = 0 #to store the lines data= for each in fh: # To check whether the line have more than two elements space seperated if each.startswith("From") and len(each.split())>2: temp=each.split() data.append(temp) for each in data: print(each) print("There were", len(data), "lines in the file with From as the first word")