All Coursera Quiz Answers

Python for everybody Week 2 Quiz Answer

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

Python Data Structures

Go to this Course: Python Data Structures


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


 

Python Data Structures Week 2 Quiz Answers

Question 1) Which of the following is a comment in Python?

  • * This is a test
  • /* This is a test */
  • // This is a test
  • # This is a test
Question 2) What does the following code print out?
print “123” + “abc”
  • 123abc
  • 123+abc
  • hello world
  • This is a syntax error because you cannot add strings
Question 3) Which of the following is a bad Python variable name?
  • spam23
  • SPAM23
  • spam_23
  • 23spam
Question 4) Which of the following is not a Python reserved word?
  • for
  • if
  • spam
  • else
Question 5) What does the following statement do?
x = x + 2
  • Exit the program
  • This would fail as it is a syntax error
  • Increase the speed of the program by a factor of 2
  • Retrieve the current value for x, add two to it and put the sum back into x
Question 6) Which of the following elements of a mathematical expression in Python is evaluated first?
  • Addition +
  • Parenthesis ( )
  • Subtraction –
  • Multiplication *
Question 7) What is the value of the following expression
42 % 10
Hint – the “%” is the remainder operator
  • 2
  • 0.42
  • 420
  • 1042
Question 8) What is the value in x after the following statement executes:
x = 1 + 2 * 3 – 8 / 4
  • 8
  • 5
  • 4
  • 15
Question 9) What value be in the variable x when the following statement is executed
x = int(98.6)
  • 6
  • 100
  • 99
  • 98
Question 10) What does the Python raw_input() function do?
  • Read the memory of the running program
  • Connect to the network and retrieve a web page.
  • Take a screen shot from an area of the screen
  • Pause the program and read data from the user

 

Week 2  Assignment 1

python code
name = raw_input("Enter your name")
print ("Hello" + ' ' + name) 

# 'space' to add space between words, and () to make python 3 print statement

 

Assignment 2

# 2.3 Write a program to prompt the user for hours and rate per hour using raw_input to compute gross pay.
# Use 35 hours and a rate of 2.75 per hour to test the program (the pay should be 96.25). 
# You should use raw_input to read a string and float() to convert the string to a number.
# Do not worry about error checking or bad user data.
# This first line is provided for you
hrs = raw_input("Enter Hours:")
rate = raw_input("Enter Rate:")
hrs = float(hrs)
rate = float(rate)
pay = hrs*rate
print pay