Podcast
Questions and Answers
Write a Python solution that accepts three integer inputs representing the number of times an employee travels to a job site. Output the total distance traveled to two decimal places given the following miles per employee commute to the job site:
Employee A: 15.62 miles
Employee B: 41.85 miles
Employee C: 32.67 miles
The solution output should be in the format
Distance: total_miles_traveled miles
Write a Python solution that accepts three integer inputs representing the number of times an employee travels to a job site. Output the total distance traveled to two decimal places given the following miles per employee commute to the job site: Employee A: 15.62 miles Employee B: 41.85 miles Employee C: 32.67 miles The solution output should be in the format Distance: total_miles_traveled miles
travels = {"A": int(input()), "B": int(input()), "C": int(input())} miles_per_employee = {"A": 15.62, "B":41.85, "C": 32.67} total_miles_traveled = sum(travels[employee] * miles_per_employee[employee] for employee in travels) print(f"Distance: {total_miles_traveled:.2f} miles")
Write a Python solution that accepts an integer input representing any number of ounces. Output the converted total number of tons, pounds, and remaining ounces based on the input ounces value. There are 16 ounces in a pound and 2,000 pounds in a ton.
The solution output should be in the format
Tons: value_1 Pounds: value_2 Ounces: value_3
Write a Python solution that accepts an integer input representing any number of ounces. Output the converted total number of tons, pounds, and remaining ounces based on the input ounces value. There are 16 ounces in a pound and 2,000 pounds in a ton. The solution output should be in the format Tons: value_1 Pounds: value_2 Ounces: value_3
ounces = int(input()) value_1 = ounces // (16 * 2000) value_2 = (ounces % (16 * 2000)) // 16 value_3 = ounces % 16 print(f"Tons: {value_1}") print(f"Pounds: {value_2}") print(f"Ounces: {value_3}")
Write a Python solution that accepts an integer input representing the index value for any any of the five elements in the following list:
various_data_types = [516, 112.49, True, "meow", ("Western", "Governors", "University"), {"apple": 1, "pear": 5}]
Using the built-in function type() and getting its name by using the .name attribute, output data type (e.g., int", "float", "bool", "str") based on the input index value of the list element.
The solution output should be in the format
Element index_value: data_type
Write a Python solution that accepts an integer input representing the index value for any any of the five elements in the following list:
various_data_types = [516, 112.49, True, "meow", ("Western", "Governors", "University"), {"apple": 1, "pear": 5}]
Using the built-in function type() and getting its name by using the .name attribute, output data type (e.g., int", "float", "bool", "str") based on the input index value of the list element.
The solution output should be in the format
Element index_value: data_type
index_value = int(input()) data_type = type(various_data_types[index_value]).name print(f"Element {index_value}: {data_type}")
Write a Python solution that accepts any three integer inputs representing the base (b1
, b2
) and height (h
) measurements of a trapezoid in meters. Output the exact area of the trapezoid in square meters as a float value. The exact area of a trapezoid can be calculated by finding the average of the two base measurements, then multiplying by the height measurement.
Trapezoid Area Formula: $A = [(b1 + b2) / 2] * h$
The solution output should be in the format
Trapezoid area: area_value square meters
Write a Python solution that accepts any three integer inputs representing the base (b1
, b2
) and height (h
) measurements of a trapezoid in meters. Output the exact area of the trapezoid in square meters as a float value. The exact area of a trapezoid can be calculated by finding the average of the two base measurements, then multiplying by the height measurement.
Trapezoid Area Formula: $A = [(b1 + b2) / 2] * h$
The solution output should be in the format
Trapezoid area: area_value square meters
Signup and view all the answers
Write a Python solution that accepts five integer inputs. Output the sum of the five inputs three times, converting the inputs to the requested data type prior to finding the sum.
First output: sum of five inputs maintained as integer values
Second output: sum of five inputs converted to float values
Third output: sum of five inputs converted to string values (concatenate)
The solution output should be in the format
Integer: integer_sum_value Float: float_sum_value String: string_sum_value
Write a Python solution that accepts five integer inputs. Output the sum of the five inputs three times, converting the inputs to the requested data type prior to finding the sum.
First output: sum of five inputs maintained as integer values
Second output: sum of five inputs converted to float values
Third output: sum of five inputs converted to string values (concatenate)
The solution output should be in the format
Integer: integer_sum_value Float: float_sum_value String: string_sum_value
Signup and view all the answers
Write a Python solution that accepts an integer input representing a 9-digit unformatted student identification number. Output the identification number as a string with no spaces.
The solution output should be in the format
111-22-3333
Write a Python solution that accepts an integer input representing a 9-digit unformatted student identification number. Output the identification number as a string with no spaces.
The solution output should be in the format
111-22-3333
Signup and view all the answers
Write a Python solution that accepts one integer input representing the index value for any of the string elements in the following list:
frameworks = ["Django", "Flask", "CherryPy", "Bottle", "Web2Py", "TurboGears"]
Output the string element of the index value entered. The solution should be placed in a try
block and implement an exception of "Error" if an incompatible integer input is provided.
The solution output should be in the format
frameworks_element
Write a Python solution that accepts one integer input representing the index value for any of the string elements in the following list:
frameworks = ["Django", "Flask", "CherryPy", "Bottle", "Web2Py", "TurboGears"]
Output the string element of the index value entered. The solution should be placed in a try
block and implement an exception of "Error" if an incompatible integer input is provided.
The solution output should be in the format
frameworks_element
Signup and view all the answers
Write a Python solution that accepts an integer input representing water temperature in degrees Fahrenheit. Output a description of the water state based on the following scale:
If the temperature is below 33° F, the water is "Frozen".
If the water is between 33° F and 80° F (including 33), the water is "Cold".
If the water is between 80° F and 115° F (including 80), the water is "Warm".
If the water is between 115° F and 211° (including 115) F, the water is "Hot".
If the water is greater than or equal to 212° F, the water is "Boiling".
Additionally, output a safety comment only during the following circumstances:
If the water is exactly 212° F, the safety comment is "Caution: Hot!"
If the water temperature is less than 33° F, the safety comment is "Watch out for ice!"
The solution output should be in the format
water_state optional_safety_comment
Write a Python solution that accepts an integer input representing water temperature in degrees Fahrenheit. Output a description of the water state based on the following scale:
If the temperature is below 33° F, the water is "Frozen".
If the water is between 33° F and 80° F (including 33), the water is "Cold".
If the water is between 80° F and 115° F (including 80), the water is "Warm".
If the water is between 115° F and 211° (including 115) F, the water is "Hot".
If the water is greater than or equal to 212° F, the water is "Boiling".
Additionally, output a safety comment only during the following circumstances:
If the water is exactly 212° F, the safety comment is "Caution: Hot!"
If the water temperature is less than 33° F, the safety comment is "Watch out for ice!"
The solution output should be in the format
water_state optional_safety_comment
Signup and view all the answers
Flashcards
Total Distance Calculation
Total Distance Calculation
Calculate total miles from employee travel inputs multiplied by their commute distances.
Distance Traveled Code
Distance Traveled Code
Uses inputs for number of trips to compute total travel distance.
Ounces to Tons Conversion
Ounces to Tons Conversion
Convert ounces input to tons, pounds, and remainder ounces.
Weight Conversion Code
Weight Conversion Code
Signup and view all the flashcards
Data Type by Index
Data Type by Index
Signup and view all the flashcards
Data Type Identification Code
Data Type Identification Code
Signup and view all the flashcards
Trapezoid Area Formula
Trapezoid Area Formula
Signup and view all the flashcards
Trapezoid Area Calculation
Trapezoid Area Calculation
Signup and view all the flashcards
Sum of Five Integers
Sum of Five Integers
Signup and view all the flashcards
Type Conversion Output
Type Conversion Output
Signup and view all the flashcards
Student ID Formatting
Student ID Formatting
Signup and view all the flashcards
Safe ID Checks
Safe ID Checks
Signup and view all the flashcards
Web Frameworks List
Web Frameworks List
Signup and view all the flashcards
Framework Index Code
Framework Index Code
Signup and view all the flashcards
Water State Determination
Water State Determination
Signup and view all the flashcards
Temperature Conditionals
Temperature Conditionals
Signup and view all the flashcards
Safety Comments for Water
Safety Comments for Water
Signup and view all the flashcards
Input Collection for Calculations
Input Collection for Calculations
Signup and view all the flashcards
List Element Types
List Element Types
Signup and view all the flashcards
Average in Geometry
Average in Geometry
Signup and view all the flashcards
Modulus Operator
Modulus Operator
Signup and view all the flashcards
Error Handling in Python
Error Handling in Python
Signup and view all the flashcards
Function Printing
Function Printing
Signup and view all the flashcards
Floating Point Arithmetic
Floating Point Arithmetic
Signup and view all the flashcards
Concatenation in Strings
Concatenation in Strings
Signup and view all the flashcards
Integer Division
Integer Division
Signup and view all the flashcards
Conversion Between Types
Conversion Between Types
Signup and view all the flashcards
Summation Logic
Summation Logic
Signup and view all the flashcards
Logical Control Flow
Logical Control Flow
Signup and view all the flashcards
Study Notes
Python Programming Practice Test 2 - Study Notes
-
Employee Travel Distance Calculation:
- Collects integer inputs for employee travel frequencies ('A', 'B', 'C').
- Uses a dictionary for employee travel costs {'A': 15.62, 'B': 41.85, 'C': 32.67}.
- Calculates total distance using a generator expression.
- Prints the total distance to two decimal places in the format "Distance: total_miles_traveled miles".
-
Ounces to Tons, Pounds, and Ounces Conversion:
- Takes integer input for ounces.
- Calculates tons, pounds, and remaining ounces using integer division and modulo.
- Prints the results in the format "Tons: value_1 Pounds: value_2 Ounces: value_3".
-
Determining Data Type by Index:
- Receives an integer input representing an index in a predefined list ("various_data_types").
- Uses
type()
to get the data type and its name (__name__
). - Prints the result in the format "Element index_value: data_type".
-
Trapezoid Area Calculation:
- Takes integer inputs for base 1 (b1), base 2 (b2), and height (h) in meters.
- Calculates the area using the formula:
area = ((b1 + b2) / 2) * h
. - Prints the area as a float in the format "Trapezoid area: area_value square meters".
-
Sum of Five Inputs (Different Types):
- Takes five integer inputs.
- Calculates the sum as an integer, float, and string concatenation.
- Prints the results in the format "Integer: integer_sum_value Float: float_sum_value String: string_sum_value".
-
Outputting a 9-digit Student ID:
- Accepts a 9-digit integer student ID.
- Outputs the ID as a string without spaces in the format required: "111-22-3333" (unclear how formatting works; text only shows formatting).
-
Handling List Element Retrieval by Index (Error Handling):
- Takes an integer input for an index in the list "frameworks".
- Uses a
try-except
block to handle potentialValueError
(user input error) andIndexError
(index out of range). - Prints the element or "Error" if an error occurred.
-
Water Temperature State and Safety Comment:
- Takes an integer water temperature input in degrees Fahrenheit.
- Determines water state ("Frozen", "Cold", "Warm", "Hot", "Boiling") based on temperature ranges.
- Prints the state and safety comment (extra comment for temperature limits or safety situations).
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
Test your knowledge of Python programming with this interactive quiz. It covers topics such as employee travel distance calculation, unit conversions, and data type identification. Ideal for students looking to reinforce their programming skills.