







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
D335 WGU D335 EXAM D335 INTRODUCTION TO PROGRAMMING IN PYTHON OA OBJECTIVE.pdf
Typology: Exams
1 / 13
This page cannot be seen from the preview
Don't miss anything!








1 | P a g e
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. miles Employee C: 32.67 miles The solution output should be in the format Distance: total_miles_traveled miles - โโโ Correct Answer > travels = D "A": int(input()), "B": int(input()), "C": int(input())
2 | P a g e
} miles_per_employee = D"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: Dtotal_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: Dvalue_1}") print(f"Pounds: Dvalue_2}") print(f"Ounces: Dvalue_3}")
Create a solution that accepts an integer input representing the index value for any any of the five elements in the following list:
4 | P a g e
print(f"Trapezoid area: Darea_value} square meters")
Create a 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 - โโโ Correct Answer > num1 = int(input()) num2 = int(input()) num3 = int(input()) num4 = int(input()) num = 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: Dinteger_sum_value}") print(f"Float: Dfloat_sum_value}")
print(f"String: tDstring_sum_value}")
Create t a t solution t that t accepts t an t integer t input t representing t a t 9- tdigit tunformatted t student t identification t number. t Output t the tidentification t number t as t a t string t with t no tspaces. The t solution t output t should t be t in t the t format 111 - 22 - 3333 t - t โโโt CorrecttAnswert>t student_id t= t int(input()) tstudent_id t >= t 100000000 tand t student_id t <= t 999999999 tpart1 t= t student_id t // t 1000000 part2 t = t (student_id t // t 10000) t % t 100 tpart3 t= t student_id t % t 10000 formatted_id t = t f"Dpart1}-Dpart2}-Dpart3}" tprint(formatted_id)
Create t a t solution t that t accepts t an t integer t input t to tcompare tagainst t the t following t list: predef_list t = t [4, t -27, t 15, t 33, t -10] Output t a t Boolean t value tindicating t whether t the t input t value t is tgreater t than tthe t maximum t value tfrom t predef_list The t solution t output t should t be t in t the t format Greater t Than t Max? t Boolean_value t - t โโโ t CorrecttAnswer t> t num t = tint(input()) boolean_value t = t False
Create t a t solution t that t accepts t an t integer t input t representing twater t temperature t in t degrees t Fahrenheit. t Output t a t description t of tthe t water t state t based t on t the t following t scale: If t the t temperature t is t below t 33ยฐ t F, t the t water t is t "Frozen". If t the t water t is t between t 33ยฐ t F t and t 80ยฐ t F t (including t 33), t the t water tis t"Cold". If t the t water t is t between t 80ยฐ tF t and t 115ยฐ tF t (including t 80), t the twater tis t"Warm". If t the t water t is t between t 115ยฐ t F t and t 211ยฐ t(including t 115) t F, t the t water tis t"Hot". If t the t water t is tgreater t than t or t equal t to t212ยฐ tF, t the t water t is t"Boiling". Additionally, t output t a t safety tcomment t only t during t the tfollowing tcircumstances: If t the t water t is t exactly t 212ยฐ t F, t the tsafety t comment t is t "Caution: tHot!" If t the t water t temperature t is t less t than t33ยฐ tF, t the tsafety t comment tis t"Watch t out t for t ice!" The t solution t output t should t be t in t the t format water_state t optional_safety_comment t - t โโโ t Correct tAnswer t> temperature t = t int(input()) twater_state t = t "" toptional_safety_comment t = t ""
if t temperature t < t 33: water_state t = t "Frozen" toptional_safety_comment t = t "Watch t out t for t ice!" telif t 33 t <= t temperature t < t80: water_state t = t "Cold" elif t 80 t <= t temperature t < t 115: water_state t = t "Warm" elif t 115 t <= t temperature t < t 212: water_state t = t "Hot" elif t temperature t >= t 212: water_state t= t"Boiling" tif ttemperature t == t 212: optional_safety_comment t = t "Caution: t Hot!" tprint(water_state) if toptional_safety_comment: tprint(optional_safety_comment)
Create t a t solution t that t accepts t an t integer t input t identifying t how tmany t shares t of t stock tare t to tbe t purchased t from t the tOld t Town tStock t Exchange, t followed t by t an t equivalent t number t of t string tinputs t representing t the t stock t selections. tThe t following t dictionary tstock tlists t available t stock t selections t as t the t key t with t the t cost t per tselection tas t the t value.
If t between t ten t and t twenty t items t (inclusive) t are t purchased, t the tpurchase tgets t a t 5% tdiscount. If t twenty-one t or t more t items t are t purchased, t the t purchase t gets t a t10% t discount. Output t the t chosen t item t and t total t cost t of t the t purchase t to ttwo tdecimal t places. The t solution t output t should t be t in t the t format item_purchased t $total_purchase_cost t - t โโโ t Correct tAnswer t> item_purchased t= tinput().lower() tnum_items t = t int(input()) if t item_purchased t in t purchase: total_purchase_cost t = t purchase[item_purchased]* t num_items
if t 10 t <= t num_items t <= t 20: total_purchase_cost t = t total_purchase_cost t - t(total_purchase_cost.05) elif t num_items t >= t 21: total_purchase_cost t = t total_purchase_cost t - t(total_purchase_cost.10)
print(f"Ditem_purchased} t $Dtotal_purchase_cost:.2f}")
Create t a t solution t that t accepts t an t input t identifying t the tname t of t a ttext t file, t for t example, t "WordTextFile1.txt". t Each t text t file t contains tthree t rows t with t one t word t per t row. t Using t the t open() t function t and twrite() t and t read() t methods, t interact twith t the t input t text t file t to twrite t a t new t sentence t string t composed t of t the t three t existing twords t to t the t end t of t the t file t contents t on t a t new t line. t Output t the tnew t file t contents. The t solution t output t should t be t in t the t format word1 tword2 t word3 t sentence t - t โโโ t CorrecttAnswert>t file_name t = tinput() with t open(file_name, t 'r') t as t f: word1 t= tf.readline().strip() tword2 t= tf.readline().strip() tword3 t = t f.readline().strip() sentence t= tf"Dword1} tDword2} tDword3}" twith t open(file_name, t 'a') t as t f: tf.write(f"\nDsentence}") with t open(file_name, t 'r') t as t f: lines t= tf.read().strip() tprint(lines)
Create ta tsolution tthat taccepts tan tinput tidentifying tthe tname tof ta tCSV tfile, tfor texample, t"input1.csv". tEach tfile tcontains ttwo trows tof tcomma-separated t values. t Import t the t built-in tmodule t csv t and
factorial_value t= tmath.factorial(num) tprint(factorial_value) if t factorial_value t > t 100: Boolean_value t= tTrue tprint(Boolean_value) telse: Boolean_value t= tFalse tprint(Boolean_value)
Create t a t solution t that t accepts t an t integer t input t representing t the tage t of t a t pig. t Import t the t existing t module t pigAge t and t use t its t pre- tbuilt t pigAge_converter() t function t to tcalculate t the t human tequivalent t age t of t a t pig. t A t year t in t a t pig's t life t is t equivalent t to t five tyears t in t a t human's t life. t Output t the t human-equivalent t age t of t the tpig. The t solution t output t should t be t in t the t format input_pig_age t is t converted_pig_age t in t human t years t - t โโโ t Correct tAnswer t> t import t pigAge input_pig_age t = t int(input()) converted_pig_age t = t pigAge.pigAge_converter(input_pig_age) tprint(f"Dinput_pig_age} tis tDconverted_pig_age} tin thuman tyears")