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
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”
- hello world
- This is a syntax error because you cannot add strings
Question 3) Which of the following is a bad Python variable name?
Question 4) Which of the following is not a Python reserved word?
- spam</span >
Question 5) What does the following statement do?
x = x + 2
- Exit the program
- This would fail as it is a syntax error</span >
- Increase the speed of the program by a factor of 2</span >
- Retrieve the current value for x, add two to it and put the sum back into x</span >
Question 6) Which of the following elements of a mathematical expression in Python is evaluated first?
- Addition +
- Parenthesis ( )</span >
- Subtraction –
- Multiplication *
Question 7) What is the value of the following expression
42 % 10
Hint – the “%” is the remainder operator
Question 8) What is the value in x after the following statement executes:
x = 1 + 2 * 3 – 8 / 4
Question 9) What value be in the variable x when the following statement is executed
x = int(98.6)
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
name = raw_input(“Enter your name”)
print (“Hello” + ‘ ‘ + name) # ‘space’ to add space between words, and () to make python 3 print statement
# 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</i >
hrs = raw_input(“Enter Hours:”)
rate = raw_input(“Enter Rate:”)
hrs = float(hrs)
rate = float(rate)
pay = hrs*rate