







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
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 Answer > 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 Answer > 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
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 - โโโ Correct Answer > 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 9digit 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 Answer > 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 Answer > 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"]
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 - โโโ Correct Answer > temperature = int(input()) water_state = "" 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 Answer > 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 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 Answer > item_purchased = input().lower() num_items = int(input()) if item_purchased in purchase: total_purchase_cost = purchase[item_purchased]* num_items if 10 <= num_items <= 20: total_purchase_cost = total_purchase_cost - (total_purchase_cost.05) elif num_items >= 21: total_purchase_cost = total_purchase_cost - (total_purchase_cost.10) print(f"{item_purchased} ${total_purchase_cost:.2f}") Create a solution that accepts an input identifying the name of a text file, for example, "WordTextFile1.txt". Each text file contains three rows with one word per row. Using the open() function and write() and read() methods, interact with the input text file to write a new sentence string
composed of the three existing words to the end of the file contents on a new line. Output the new file contents. The solution output should be in the format word1 word2 word3 sentence - โโโ Correct Answer > file_name = input() with open(file_name, 'r') as f: word1 = f.readline().strip() word2 = f.readline().strip() word3 = f.readline().strip() sentence = f"{word1} {word2} {word3}" with open(file_name, 'a') as f: 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 Answer > import csv input1 = input() with open(input1, "r") as f: data = csv.reader(f) for row in data:
The solution output should be in the format input_pig_age is converted_pig_age in human years - โโโ Correct Answer > import pigAge input_pig_age = int(input()) converted_pig_age = pigAge.pigAge_converter(input_pig_age) print(f"{input_pig_age} is {converted_pig_age} in human years")