Quiz 2 - Hello World#

Instructions#

You will click on the following link to start your quiz. Do not start the quiz before your lab section. We have checks in place to ensure that you do not start the quiz early. If you do, you will receive a 0 on the quiz. Furthermore, it could be considered an academic integrity violation.

CLICK HERE TO START YOUR QUIZ IN LAB

Practicing for the Quiz#

Navigate to the assignment on the course website. Click on the rocket icon to launch the assignment in the JupyterHub.

Part 1: Entering Your Information for Credit#

To receive credit for assignments it is important we can identify your work from others. To do this we will ask you to enter your information in the following code block.

Before you begin#

Run the block of code at the top of the notebook that imports and sets up the autograder. This will allow you to check your work.

Make sure you run all your code, and run the tests. If you do not run the test you will not get credit for your work.

# Please provide your first name, last name, Drexel ID, and Drexel email. Make sure these are provided as strings. "STRINGS ARE TEXT ENCLOSED IN QUOTATION MARKS."

# In the assignments you will see sections of code that you need to fill in that are marked with ... (three dots). Replace the ... with your code.
first_name = ...
last_name = ...
drexel_id = ...
drexel_email = ...

Question 1: Importing Packages and Doing Math#

The power of python comes from the packages that are available for it. In this question, you will learn how to import packages and use them to do math.

Write a Python code to import the math package and then use it to calculate the factorial of 8. This uses the math.factorial method.

Example 1#

To help you we provide an example for you to understand the syntax required. All homework assignments will be wrapped in a function for grading purposes. For now, just ignore the def function_name(): and return lines. We will explain them later in the course. For now just focus on the code inside the function.

Example syntax:#

We provide an example solution of the following question for you to reference.

Write a Python code to import the math package and then use it to calculate the natural logarithm of 20. print the result.

# Import the math package
import math

def example_1():

   # Calculate and print the natural logarithm of 20
   log_20 = math.log(20)
   output = print(log_20)

   return output

# import required packages here

...

# This line of code defines a function
# DO NOT CHANGE THIS LINE OF CODE
def question_1():

   # Calculate the factorial of 8
   # Python is sensitive to indentation, so make your code is indented as provided
   factorial_8 = ...

   # This line of code returns variables
   # DO NOT CHANGE THIS LINE OF CODE
   return factorial_8

# This line of code calls the function
# DO NOT CHANGE THIS LINE OF CODE
factorial_8 = question_1()

Question 2: Applying Simple Mathematical Operations#

Write a Python program that calculates and prints the result of the following operations:

  • Assign a to the value of 123456

  • Assign b to the value of 7

  • Compute how many times 7 can go into 123456.

  • Compute the remainder of 123456 when divided by 7.

# This line of code defines a function
# DO NOT CHANGE THIS LINE OF CODE
def question_2():
   a = ...
   b = ...

   # how many times does b go into a?
   floor_division = ...
   
   # what is the remainder?
   remainder_result = ...

   # This line of code returns variables
   # DO NOT CHANGE THIS LINE OF CODE
   return (floor_division, remainder_result, a, b)

# This line of code calls the function
# DO NOT CHANGE THIS CODE
output = question_2()


# Print the results to help you troubleshoot if needed

Question 3: Basic Printing of Strings#

Print the following sentence in Python: Go BIRDS! Make sure to include the exclamation mark.

# This line of code defines a function
# DO NOT CHANGE THIS LINE OF CODE
def question_3():
   
   string = ...

   output = ...

   # This line of code returns variables
   # DO NOT CHANGE THIS LINE OF CODE
   return string

# This line of code calls the function
# DO NOT CHANGE THIS LINE OF CODE
output = question_3()

Question 4: Assigning Variable and Operations on Variables#

Create two variables: a and b. Assign the value 15 to a and the value 18 to b. Then, create a third variable c that stores the multiplication results of a and b.

# This line of code defines a function
# DO NOT CHANGE THIS LINE OF CODE
def question_4():
   a = ...
   b = ...
   c = ...
   
   return a, b, c  

# This line of code calls the function
# DO NOT CHANGE THIS LINE OF CODE
a, b, c = question_4()

Submitting Your Assignment#

To submit your quiz please use the following link the assignment on GitHub classroom.

Use this link to navigate to the assignment on GitHub classroom.

Please submit just your output.log file. No other files are needed.

Viewing your score#

Each log file you have uploaded will have a file with the name of your file + Grade_Report.md. You can view this file by clicking on the file name. This will show you the results of the autograder.

Make sure you run your code, and run the tests. If you do not run the test you will not get credit for your work.

Note

In python and particularly jupyter notebooks it is common that during testing you run cells in a different order, or run cells and modify them. This can cause there to be local variables needed for your solution that would not be recreated on running your code again from scratch. Your assignment will be graded based on running your code from scratch. This means before you submit your assignment you should restart the kernel and run all cells. You can do this by clicking Kernel and selecting Restart and Run All. If you code does not run as expected after restarting the kernel and running all cells it means you have an error in your code.

Fin#