Classwork 2

Python Fundamentals

Author

Byeong-Hak Choe

Published

January 28, 2026

Modified

January 27, 2026

Question 1

(a)

Using Python operations only, calculate below: \[\frac{2^5}{7 \cdot (4 - 2^3)}\]

(b)

Given:

data = [10, 2.5, "3"]

Using Python only, calculate 10 + 2.5 + 3

(c)

Given:

exam_score = {"Midterm": 78, "Final": 92}

Compute the Total Exam Score:

\[ \begin{align} \text{(Total Exam Score)} = \max\{ &0.50\times \text{(Midterm)} + 0.50\times \text{(Final)},\\ &0.33\times \text{(Midterm)} + 0.67\times \text{(Final)} \} \end{align} \]




Question 2

For each expression below, what is the value of the expression? Explain thoroughly.

(a)

20 == '20'

(b)

x = 4.0
y = .5

x < y or 3*y < x




Question 3

(a)

What will the following code print? (Answer without running it.)

status = "Gold"
cart_total = 92.5

free_shipping_levels = ["Gold", "Platinum"]

if status in free_shipping_levels:
    shipping = 0
    msg = f"Status: {status} → Free shipping! Total = ${cart_total}"
elif cart_total >= 100:
    shipping = 0
    msg = f"Spend threshold met → Free shipping! Total = ${cart_total}"
else:
    shipping = 7.99
    msg = f"Status: {status}, Total = ${cart_total} → Shipping = ${shipping}"

print(msg)

(b)

  • Fill in the blanks:
    • If name is "Geneseo" and score >= 90 → print "Geneseo high score"
    • Else if score >= 90 → print "High score"
    • Else → print "Try again"
name = "Geneseo"
score = 88

# Fill in the blanks
if ______________________________:
    print("Geneseo high score")
elif ____________________________:
    print("High score")
else:
    print("Try again")




Question 4

(a)

What will the following code print? (Do not run it—reason it out.)

nums = [10, 20, 30, 40, 50, 60, 70]

print(nums[2:6])
print(nums[:4])
print(nums[::2])
print(nums[-4:-1])

(b)

fare = "$10.00"
tip = "2.00$"
tax = "$ 0.80"

Write a Python code that uses slicing and the print() function to print out the following message:

The total trip cost is: $12.80





Question 5

list_variable = [100, 144, 169, 1000, 8]

Write a Python code that uses print() and max() functions to print out the largest value in the list, list_variable, as follows:

The largest value in the list is: 1000





Question 6

vals = [3, 2, 1, 0]
  • Use a while loop to print each value of the list [3, 2, 1, 0], one at a time.
  • Use a for loop to print each value of the list [3, 2, 1, 0], one at a time.





Question 7

  • Assign the value 7 to the variable guess_me, and the value 1 to the variable number.

  • Write a while loop that compares number with guess_me.

    • Print ‘too low’ if number is less than guess me.
    • If number equals guess_me, print ‘found it!’ and then exit the loop.
    • If number is greater than guess_me, print ‘oops’ and then exit the loop.
    • Increment number at the end of the loop.
  • Write a for loop that compares number with guess_me.

    • Print ‘too low’ if number is less than guess me.
    • If number equals guess_me, print ‘found it!’ and then exit the loop.
    • If number is greater than guess_me, print ‘oops’ and then exit the loop.
    • Increment number at the end of the loop.





Question 8

  • You are given a variable value that contains a string.
value = "$320"
  • Write a Python program to:
    1. Attempt to convert value to a floating-point number using float().
    2. If the conversion is successful, print: “You entered: ”.
    3. If the conversion fails (e.g., the value is not a valid number), print: “That’s not a valid number!”.
  • Use a try-except block to handle the potential error.





Question 9

  • Import the pandas library as pd.
  • Install the selenium library.
  • From selenium, import the functions webdriver.





Discussion

Welcome to our Classwork 2 Discussion Board! 👋

This space is designed for you to engage with your classmates about the material covered in Classwork 2.

Whether you are looking to delve deeper into the content, share insights, or have questions about the content, this is the perfect place for you.

If you have any specific questions for Byeong-Hak (@bcdanl) regarding the Classwork 2 materials or need clarification on any points, don’t hesitate to ask here.

All comments will be stored here.

Let’s collaborate and learn from each other!

Back to top