All Coursera Quiz Answers

Python for everybody Week 6 Quiz Answer

Hello Friends in this article i am gone to share Coursera Course: Python Data Structures Week 6 Quiz Answers with you..

Python Data Structures

Go to this Course: Python Data Structures


Also visit this link: Python Data Structures Week 5 Quiz Answers


 

Python Data Structures Week 6 Quiz Answers

Question 1)
What does the following Python Program print out?
str1 = "Hello"
str2 = 'there'
bob = str1 + str2
print bob
  • Hello
  • Hellothere
  • Hello
  • 0
  • there
ย 
Question 2)
What does the following Python program print out?
x = '40'
y = int(x) + 2
print y
  • x2
  • 402
  • 42
  • int402
ย 
Question 3)
How would you use the index operator [] to print out the letter q from the following string?
x = 'From [email protected]'
  • print x[9]
  • print x[q]
  • print x[7]
  • print x[8]
  • print x[-1]
Question 4)
How would you use string slicing [:] to print out ‘uct’ from the following string?
x = 'From [email protected]'
  • print x[14:3]
  • print x[14+17]
  • print x[15:3]
  • print x[15:18]
  • print x[14:17]
  • print x[14/17]
Question 5)
What is the iteration variable in the following Python code?
for letter in 'banana' :
ย  ย  ย  ย  print letter
  • for
  • print
  • letter
  • ‘banana’
  • in
Question 6)
What does the following Python code print out?
print len('banana')*7
  • -1
  • 0
  • banana banana banana banana banana banana banana
  • 42
ย 
Question 7)
How would you print out the following variable in all upper case in Python?
greet = 'Hello Bob'
  • print uc($greet);
  • print greet.upper()
  • puts greet.ucase;
  • console.log(greet.toUpperCase());
Question 8)
Which of the following is not a valid string method in Python?
  • join()
  • lstrip()
  • upper()
  • twist()
ย 
Question 9)
What will the following Python code print out?
data = 'From [email protected] Sat Janย  5 09:14:16 2008'
pos = data.find('.')
print data[pos:pos+3]
  • mar
  • Sat
  • .ma
  • 09:14
ย 
Question 10)
Which of the following string methods removes whitespace from both the beginning and end of a string?
  • strip()
  • split()
  • wsrem()
  • strtrunc()

 

Week 6 Assignment Answer

ย #6.5 Write code using find() and string slicing (see section 6.10) to extract the number at the end of the line below.
#Convert the extracted value to a floating point number and print it out.
text = "X-DSPAM-Confidence:ย  ย  0.8475";
str = 'X-DSPAM-Confidence: 0.8475'
ipos = str.find(':')
#print(ipos)
piece = str[ipos+2:]
#print(piece)
value = float(piece)
print(value)