Python Practice Problems: Variables, Data Types, and Formatting
Exercise 1: Variable Assignment, Calculation, and F-Strings

Overview:
Demonstrates fundamental Python concepts including variable declaration, value reassignment, arithmetic operations, and string formatting using f-strings.
Source Code Breakdown:
1 #Practice Problems: Single-line comment designating the section header.3 print("Exercise 1"): Prints the string literal header"Exercise 1".4 grade=93: Initializes variablegradewith integer value93.5 print("ITM_251 Grade:", grade): Prints string literal"ITM_251 Grade:"followed by the current value ofgrade(93).7 grade=100: Reassigns variablegradeto integer value100, replacing the previous value.8 print("QMB_210 Grade:", grade): Prints string literal"QMB_210 Grade:"followed by the updated value ofgrade(100).10 average_score=((93+100)/2): Calculates the arithmetic average:11 print("Average Score:", average_score): Prints string literal"Average Score:"followed by96.5.13 print("Julie's Average Score is", average_score): Prints text string alongside the evaluated variable96.5.15 name="Julie": Assigns string literal"Julie"to variablename.16 score=93: Assigns integer93to variablescore.17 class_name="ITM_251": Assigns string literal"ITM_251"to variableclass_name.18 print(f"Yay, {name}! You scored a {score} in {class_name}."): Uses formatted string literal (f-string) to interpolate variable values directly inside curly braces{}.
Console Output:
Exercise 1ITM_251 Grade: 93QMB_210 Grade: 100Average Score: 96.5Julie's Average Score is 96.5Yay, Julie! You scored a 93 in ITM_251.
Key Technical Takeaways:
Variable Reassignment: Variables are updated sequentially; subsequent assignments overwrite previous stored values.
Division Output: Arithmetic division
/in Python evaluates to a floating-point number (96.5).F-String Interpolation: Prefixing a string with
fallows expressions inside curly braces{}to be dynamically inserted into string output.
Exercise 2: Boolean Data Type and Type Inspection

Overview:
Demonstrates Boolean variable instantiation and utilization of the built-in
type()function to evaluate data types at runtime.
Source Code Breakdown:
1 print("Exercise 2"): Prints section header string"Exercise 2".3 winter= False: Assigns Boolean keywordFalseto variablewinter.4 print(winter,type(winter)): Prints the value stored inwinterfollowed by the evaluation oftype(winter).
Console Output:
Exercise 2False <class 'bool'>
Key Technical Takeaways:
Boolean Data Type:
boolobjects represent one of two binary logical states:TrueorFalse(case-sensitive keywords).Type Inspection: Calling
type()returns the class type of any Python object, evaluating to<class 'bool'>for Booleans.
Exercise 3: Multi-Variable Calculation and Format Specifiers
Overview:
Demonstrates arithmetic operations combining floating-point and integer numbers, alongside numeric string formatting specifiers.
Source Code Breakdown:
1 print("Exercise 3"): Prints header string"Exercise 3".3 item_name = "Widget": Assigns string"Widget"to variableitem_name.4 price=15.99: Assigns float value15.99to variableprice.5 quantity = 4: Assigns integer4to variablequantity.7 total_cost = price*quantity: Computes total cost via multiplication:9 print(f"Item: {item_name}, Quantity: {quantity}, Total Cost: ${total_cost:,.2f}"): Formats total cost within an f-string using specifier:,.2f.
Console Output:
Exercise 3Item: Widget, Quantity: 4, Total Cost: $63.96
Key Technical Takeaways:
Mixed-Type Multiplication: Multiplying a float (
15.99) by an integer (4) returns a float (63.96).F-String Formatting Specifier (
:,.2f)::initiates the formatting options.,adds thousands separators for comma delimitation..2fspecifies floating-point formatting constrained to exactly two decimal places.