






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 commute = {
'Employee A': 15.62,
'Employee B': 41.85,
'Employee C': 32.
}
travels = {
'Employee A': int(input()),
'Employee B': int(input()), 'Employee C': int(input())
}
t_d_t = sum(commute[employee]*travels[employee] for employee in travels)
print(f'Distance: {t_d_t:.2f} miles') << correct answer >>Create a Python solution to the following task.
Ensure that the solution produces output in exactly the same format shown in the sample(s) below, including capitalization and whitespace.
Task:
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 opp = 16
top = 2000
ounces = int(input())
tons = ounces // (opp * top)
ro = ounces % (opp * top)
pounds = ro // opp
ro %= opp
print(f'Tons: {tons}')
print(f'Pounds: {pounds}')
print(f'Ounces: {ro}') << correct answer >>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 I_V = int(input())
if -1 <= I_V < len(various_data_types):
element = various_data_types [I_V]
D_T_N = str(type(element)).split("'")[1]
print(f' Element {I_V}: {D_T_N}') << correct answer >>Create a 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
format_id_num = f'{id_num // 1000000}-{(id_num // 10000) % 100}-{id_num % 10000:04d}'
print(format_id_num) << correct answer >>Task:
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 user = int(input())
greater_than = user > max(predef_list)
print(f'Greater Than Max? {greater_than}') << correct answer >>Task:
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 try:
index = int(input()) if 0 <= index < len(frameworks): print(frameworks[index]) else:
raise ValueError("Error")
except ValueError:
print("Error") << correct answer >>Task:
Create a 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 n33), nthe nwater nis n"Cold". n
If nthe nwater nis nbetween n80° nF nand n115° nF n(including n80), nthe nwater nis n"Warm". n
If nthe nwater nis nbetween n115° nF nand n211° n(including n115) nF, nthe nwater nis n"Hot". n
If nthe nwater nis ngreater nthan nor nequal nto n212° nF, nthe nwater nis n"Boiling". n
Additionally, noutput na nsafety ncomment nonly nduring nthe nfollowing ncircumstances:
nIf nthe nwater nis nexactly n212° nF, nthe nsafety ncomment nis n"Caution: nHot!" n
If nthe nwater ntemperature nis nless nthan n33° nF, nthe nsafety ncomment nis n"Watch nout
nfor nice!" nThe nsolution noutput nshould nbe nin nthe nformat n
water_state n
optional_safety_comment n temperature n= nint(input()) n
if ntemperature n< n33: n
nwater_state n= n"Frozen" n
nsafety_comment n= n"Watch nout nfor nice!" n
elif n 33 n<= ntemperature n<= n80: n
nwater_state n= n"Cold" n
nsafety_comment n= nNone n
elif n 80 n< ntemperature n<= n115: n
nwater_state n= n"Warm" n
nsafety_comment n= nNone n
elif n 115 n< ntemperature n<= n211: n
nwater_state n= n"Hot" n
nsafety_comment n= nNone n
else: n
nwater_state n= n"Boiling" n
nsafety_comment n= n"Caution: nHot!" n
if nsafety_comment: n
nprint(f"{water_state}\n{safety_comment}") n
else: n
nprint(water_state) n<< ncorrect nanswer n>>Task: n
item_purchased n$total_purchase_cost npurchase n= n{"bananas": n1.85, n"steak": n19.99, n"cookies": n4.52, n"celery": n2.81, n"milk": n4.34} n
item_name n= ninput().lower() n num_items n= nint(input()) n
if nnum_items n< n10: n
ntotal_cost n= npurchase[item_name] n* nnum_items n
elif n 10 n<= nnum_items n<= n20: n
ntotal_cost n= n(purchase[item_name] n* nnum_items) n*
n0.95 nelse: n
ntotal_cost n= n(purchase[item_name] n* nnum_items) n*
n0.90 n
print(f"{item_name} n${total_cost:.2f}") n<< ncorrect nanswer n>>Task: n
Create na nsolution nthat naccepts nan ninput nidentifying nthe nname nof na ntext nfile, nfor nexample, n "WordTextFile1.txt". nEach ntext nfile ncontains nthree nrows nwith none nword nper nrow. nUsing nthe nopen() nfunction nand nwrite() nand nread() nmethods, ninteract nwith nthe ninput ntext nfile nto nwrite na nnew nsentence nstring ncomposed nof nthe nthree nexisting nwords nto nthe nend nof nthe nfile ncontents non na nnew nline. nOutput nthe nnew nfile ncontents. n
The nsolution noutput nshould nbe nin nthe nformat n
word1 n
word2 n
word3 n
sentence n file_name n= ninput() n
with nopen(file_name, n'r') nas nfile: n
nlines n= nfile.readlines() n
nif nlen(lines) n== n3: n nword1, nword2, nword3 n= n[line.strip() nfor nline nin
nlines] n nelse: n
nprint("Input nfile nshould ncontain nexactly nthree
nwords.") n
nexit(1) n
sentence n= nf"{word1} n{word2}
n{word3}" n
with nopen(file_name, n'a') nas
nfile: n
nfile.write('\n' n+ nsentence) n
with nopen(file_name, n'r') nas nfile: n
nupdated_contents n= nfile.read() n nprint(updated_contents) n<< ncorrect nanswer n>>Task: n
Create na nsolution nthat naccepts nan ninteger ninput. nImport nthe nbuilt-in nmodule nmath nand nuse nits
nfactorial() nmethod nto ncalculate nthe nfactorial nof nthe ninteger ninput. nOutput nthe nvalue nof nthe
nfactorial, nas nwell nas na nBoolean nvalue nidentifying nwhether nthe nfactorial noutput nis ngreater nthan
n100. n
The nsolution noutput nshould nbe nin nthe nformat n
factorial_value nBoolean_value nimport nmath n
user_input n= nint(input()) n
input_fact n= nmath.factorial(user_input) n
is_greater100 n= nTrue nif ninput_fact n> n 100 nelse nFalse n
print(input_fact) n
print(is_greater100) n<< ncorrect nanswer n>>Task: n
Create na nsolution nthat naccepts nan ninteger ninput nrepresenting nthe nage nof na npig. nImport nthe
nexisting nmodule npigAge nand nuse nits npre-built npigAge_converter() nfunction nto ncalculate nthe nhuman
nequivalent nage nof na npig. nA nyear nin na npig's nlife nis nequivalent nto nfive nyears nin na nhuman's nlife.
nOutput nthe nhuman-equivalent nage nof nthe npig. n
The nsolution noutput nshould nbe nin nthe nformat n
input_pig_age nis nconverted_pig_age nin nhuman nyears n import npigAge n
input_pig_age n= nint(input()) n
nfunction. n
print(f'{input_pig_age} nis n{converted_pig_age} nin nhuman nyears') n<< ncorrect nanswer n>> n