






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
WGUD335:INTRODUCTION TO PROGRAMMING IN PYTHON HOME PRACTICE TEST 2026 WITH VERIFIED SOLUTIONS.
Typology: Exams
1 / 12
This page cannot be seen from the preview
Don't miss anything!







Create a 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. 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 - Correct Answers- 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") Create a 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 - Correct Answers- 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}") Create a 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 - Correct Answers- index_value = int(input()) data_type = type(various_data_types[index_value]).name print(f"Element {index_value}: {data_type}")
num1 = int(input()) num2 = int(input()) num3 = int(input()) num4 = int(input()) num5 = int(input()) integer_sum_value = num1 + num2 + num3 + num4 + num float_sum_value = float(num1) + float(num2) + float(num3) + float(num4) + float(num5) string_sum_value = str(num1) + str(num2) + str(num3) + str(num4) + str(num5) print(f"Integer: {integer_sum_value}") print(f"Float: {float_sum_value}") print(f"String: {string_sum_value}") Create a 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 - Correct Answers- student_id = int(input()) student_id >= 100000000 and student_id <= 999999999 part1 = student_id // 1000000 part2 = (student_id // 10000) % 100 part3 = student_id % 10000 formatted_id = f"{part1}-{part2}-{part3}" print(formatted_id)
Create a solution that accepts an integer input to compare against the following list: predef_list = [4, -27, 15, 33, -10] Output a Boolean value indicating whether the input value is greater than the maximum value from predef_list The solution output should be in the format Greater Than Max? Boolean_value - Correct Answers- num = int(input()) boolean_value = False max_value = max(predef_list) if num > max_value: boolean_value = True print(f"Greater Than Max? {boolean_value}") else: print(f"Greater Than Max? {boolean_value}") Create a 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 - Correct Answers- try:
optional_safety_comment = "" if temperature < 33: water_state = "Frozen" optional_safety_comment = "Watch out for ice!" elif 33 <= temperature < 80: water_state = "Cold" elif 80 <= temperature < 115: water_state = "Warm" elif 115 <= temperature < 212: water_state = "Hot" elif temperature >= 212: water_state = "Boiling" if temperature == 212: optional_safety_comment = "Caution: Hot!" print(water_state) if optional_safety_comment: print(optional_safety_comment) Create a solution that accepts an integer input identifying how many shares of stock are to be purchased from the Old Town Stock Exchange, followed by an equivalent number of string inputs representing the stock selections. The following dictionary stock lists available stock selections as the key with the cost per selection as the value. stocks = {'TSLA': 912.86 , 'BBBY': 24.84, 'AAPL': 174.26, 'SOFI': 6.92, 'KIRK': 8.72, 'AURA': 22.12, 'AMZN': 141.28, 'EMBK': 12.29, 'LVLU': 2.33} Output the total cost of the purchased shares of stock to two decimal places. The solution output should be in the format
Total price: $cost_of_stocks - Correct Answers- num_stock = int(input()) cost_of_stocks = 0 for _ in range(num_stock): stock_selection = input() if stock_selection in stocks: cost_of_stocks += stocks[stock_selection] print(f"Total price: ${cost_of_stocks:.2f}") Create a solution that accepts a string input representing a grocery store item and an integer input identifying the number of items purchased on a recent visit. The following dictionary purchase lists available items as the key with the cost per item as the value. purchase = {"bananas": 1.85, "steak": 19.99, "cookies": 4.52, "celery": 2.81, "milk": 4.34} Additionally, If fewer than ten items are purchased, the price is the full cost per item. If between ten and twenty items (inclusive) are purchased, the purchase gets a 5% discount. If twenty-one or more items are purchased, the purchase gets a 10% discount. Output the chosen item and total cost of the purchase to two decimal places. The solution output should be in the format item_purchased $total_purchase_cost - Correct Answers- item_purchased = input().lower() num_items = int(input())
f.write(f"\n{sentence}") with open(file_name, 'r') as f: lines = f.read().strip() print(lines) Create a solution that accepts an input identifying the name of a CSV file, for example, "input1.csv". Each file contains two rows of comma-separated values. Import the built-in module csv and use its open() function and reader() method to create a dictionary of key:value pairs for each row of comma-separated values in the specified file. Output the file contents as two dictionaries. The solution output should be in the format {'key': 'value', 'key': 'value', 'key': 'value'} {'key': 'value', 'key': 'value', 'key': 'value'} - Correct Answers- import csv input1 = input() with open(input1, "r") as f: data = csv.reader(f) for row in data: even = [row[i].strip() for i in range(0, len(row), 2)] odd = [row[i].strip() for i in range(1, len(row), 2)] pair = dict(zip(even, odd)) print(pair) Create a solution that accepts an integer input. Import the built-in module math and use its factorial() method to calculate the factorial of the integer input. Output the value of the factorial, as well as a Boolean value
identifying whether the factorial output is greater than
The solution output should be in the format factorial_value Boolean_value - Correct Answers- import math num= int(input()) factorial_value = math.factorial(num) print(factorial_value) if factorial_value > 100: Boolean_value = True print(Boolean_value) else: Boolean_value = False print(Boolean_value) Create a solution that accepts an integer input representing the age of a pig. Import the existing module pigAge and use its pre-built pigAge_converter() function to calculate the human equivalent age of a pig. A year in a pig's life is equivalent to five years in a human's life. Output the human-equivalent age of the pig. The solution output should be in the format input_pig_age is converted_pig_age in human years - Correct Answers- import pigAge input_pig_age = int(input()) converted_pig_age = pigAge.pigAge_converter(input_pig_age)