Lab

1.3.2. Lab#

  • Use this assignment to practice the chapter’s concepts and coding skills in runnable Python code.

  • Sign in from the account menu before you start working on the assignment.

  • Write and run your code directly in the coding cells.

  • Multiple submissions are allowed. The highest score is kept.

### Question 1: CRISP-DM phases
# A retail manager wants to predict which customers are likely to stop buying.
# Store the first three CRISP-DM phases in variables named phase_1, phase_2, and phase_3.
# Store the last three phases in variables named phase_4, phase_5, and phase_6.
# Then print the first phase and the last phase.
### Your code starts here.



### Your code ends here.

Hide code cell source

### Solution
phase_1 = "Business Understanding"
phase_2 = "Data Understanding"
phase_3 = "Data Preparation"
phase_4 = "Modeling"
phase_5 = "Evaluation"
phase_6 = "Deployment"

print("First phase:", phase_1)
print("Last phase:", phase_6)
First phase: Business Understanding
Last phase: Deployment
### Question 2: Data science tool categories
# Create four variables named data_management_tool, data_manipulation_tool,
# data_analysis_tool, and data_visualization_tool.
# Give each variable one tool example from Section 1.1.
# Then print the visualization tool.
### Your code starts here.



### Your code ends here.

Hide code cell source

### Solution
data_management_tool = "SQL database"
data_manipulation_tool = "pandas"
data_analysis_tool = "scikit-learn"
data_visualization_tool = "Matplotlib"

print("Visualization tool:", data_visualization_tool)
Visualization tool: Matplotlib
### Question 3: Decimal to binary conversion
# Convert the decimal number 13 to binary using base-2 place values.
# Store each binary digit in a variable named bit_3, bit_2, bit_1, and bit_0.
# Store the full binary answer in a variable named manual_binary.
# Then print manual_binary.
# Check your answer by printing bin(13).
decimal_number = 13
### Your code starts here.



### Your code ends here.

Hide code cell source

### Solution
decimal_number = 13
bit_3 = 1  # 8s place
bit_2 = 1  # 4s place
bit_1 = 0  # 2s place
bit_0 = 1  # 1s place

manual_binary = "0b1101"

print("Manual conversion:", manual_binary)
print("Python check:", bin(decimal_number))
Manual conversion: 0b1101
Python check: 0b1101
### Question 4: Expressions and statements
# The values below describe one customer order.
# Write assignment statements that calculate subtotal, tax, and total.
# Then print all three values rounded to 2 decimal places.
# Use round(value, 2) to round a number to 2 decimal places.
unit_price = 18.75
quantity = 4
tax_rate = 0.0825
### Your code starts here.



### Your code ends here.

Hide code cell source

### Solution
unit_price = 18.75
quantity = 4
tax_rate = 0.0825

subtotal = unit_price * quantity
tax = subtotal * tax_rate
total = subtotal + tax

print("Subtotal:", round(subtotal, 2))
print("Tax:", round(tax, 2))
print("Total:", round(total, 2))
Subtotal: 75.0
Tax: 6.19
Total: 81.19
### Question 5: Number systems and character encoding
# A simple inventory system uses product code "C" and item number 64.
# Save the decimal code for "C" in c_decimal using ord().
# Save the binary representation of c_decimal in c_binary using bin().
# Save the hexadecimal representation of item_number in item_hex using hex().
# Print c_decimal, c_binary, and item_hex.
item_number = 64
### Your code starts here.



### Your code ends here.

Hide code cell source

### Solution
item_number = 64
c_decimal = ord("C")
c_binary = bin(c_decimal)
item_hex = hex(item_number)

print("C decimal:", c_decimal)
print("C binary:", c_binary)
print("Item hex:", item_hex)
C decimal: 67
C binary: 0b1000011
Item hex: 0x40