WGU D335 PRACTICETEST 2WITHCOMPLETESOLUTIONS
v v v v v v v
1. CreateBGaBGsolutionBGthatBGacceptsBGthreeBGintegerBGinputsBGrepresentingBGthe
v v v v v v v v v
BGnumber BGof BGtimes BGan BGemployee BGtravels BGto BGa BGjob BGsite. BGOutput BGthe
v v v v v v v v v v v v
BGtotal BGdistance BGtraveled BGto BGtwo BGdecimal BGplacesBGgiven BGtheBGfollowing
v v v v v v v v v v
BGmiles BGper BGemployee BGcommute BGto BGthe BGjob BGsite. BGOutput BGthe BGtotal
v v v v v v v v v v v
BGdistance BGtraveled BGto BGtwo BGdecimal BGplaces BGgiven BGthe BGfollowing
v v v v v v v v v
BGmiles BGper BGemployee BGcommute BGto BGthe BGjob BGsite:
v v v v v v v v
EmployeeBGA:BG15.62 v v
BGmiles BGEmployee BGB:
v v v
BG41.85 BGmiles
v v
Employee BGC:BG32.67 BGmiles:BGtimes_traveledA BG= BGint(input())
v v v v v v
BGtimes_traveledB BG= BGint(input())
v v v
times_traveledCBG=BGint(input()) v v
BGemployeeA BG= BG15.62 BG#miles
v v v v
BGemployeeB BG= BG41.85 BG#miles
v v v v
BGemployeeC BG= BG32.67 BG#miles
v v v v
distance_traveledA BG= BGtimes_traveledA BG* v v v
BGemployeeA
v BGdistance_traveledB BG= v v
BGtimes_traveledB
v BG* BGemployeeB v v
BGdistance_traveledC
v BG= BGtimes_traveledC BG* v v v
BGemployeeC
v
total_miles_traveled BG= BGdistance_traveledA BG+ BGdistance_traveledB BG+ v v v v v
BGdistance_trav- BGeledC
v v
print('Distance:BG{:.2f} BGmiles'.format(total_miles_traveled))
v v
1
BG/
v
BG12
v
, 2. CreateBGaBGsolutionBGthatBGacceptsBGanBGinputBGidentifyingBGtheBGnameBGofBGa
v v v v v v v v v v v
BGtextBGfile,BGfor BGexample,BG"WordTextFile1.txt".BGEachBGtextBGfileBGcontains
v v v v v v v v v
BGthreeBGrowsBGwithBGoneBGword BGper BGrow. BGUsing BGthe BGopen() BGfunction
v v v v v v v v v v v
BGand BGwrite() BGand BGread() BGmethods, BGinteract BGwith BGthe BGinput BGtext BGfile
v v v v v v v v v v v
BGto BGwrite BGa BGnew BGsentence BGstring BGcomposed BGof BGthe BGthree BGexisting
v v v v v v v v v v v
BGwords BGto BGthe BGend BGof BGthe BGfile BGcontents BGon BGa BGnew BGline. BGOutput
v v v v v v v v v v v v v
BGthe BGnew BGfile BGcontents.: BGfile_name BG= BGinput()
v v v v v v v
with BGopen(file_name, BG'r') BGas BGf:
v v v v
word1 BG= v
BGstr(f.readline()).strip()
v
BGword2 v BG= v
BGstr(f.readline()).strip()
v
BGword3 v BG= v
BGstr(f.readline()).strip()
v
f BG= BGopen(file_name, BG'r')
v v v
BGlinesBG=
v v
BGf.read().splitlines() BGlines
v v
BG= BG' BG'.join(lines)
v v v
BGf.close()
v
print(f'{word1}\n{word2}\n{word3}\n{lines}')
3. Create BGa BGsolution BGthat BGaccepts BGan BGinteger BGinput BGrepresenting BGany
v v v v v v v v v
BGnumber BGof BGounces. BGOutput BGthe BGconverted BGtotal BGnumber BGof BGtons,
v v v v v v v v v v
BGpounds, BGand BGremaining BGounces BGbased BGon BGthe BGinput BGounces BGvalue.
v v v v v v v v v v
BGThere BGare BG16 BGounces BGin BGa BGpound BGand BG2,000 BGpounds BGin BGa BGton.:
v v v v v v v v v v v v v
BGounces_per_pound BG= BG16
v v v
2
BG/
v
BG12
v
v v v v v v v
1. CreateBGaBGsolutionBGthatBGacceptsBGthreeBGintegerBGinputsBGrepresentingBGthe
v v v v v v v v v
BGnumber BGof BGtimes BGan BGemployee BGtravels BGto BGa BGjob BGsite. BGOutput BGthe
v v v v v v v v v v v v
BGtotal BGdistance BGtraveled BGto BGtwo BGdecimal BGplacesBGgiven BGtheBGfollowing
v v v v v v v v v v
BGmiles BGper BGemployee BGcommute BGto BGthe BGjob BGsite. BGOutput BGthe BGtotal
v v v v v v v v v v v
BGdistance BGtraveled BGto BGtwo BGdecimal BGplaces BGgiven BGthe BGfollowing
v v v v v v v v v
BGmiles BGper BGemployee BGcommute BGto BGthe BGjob BGsite:
v v v v v v v v
EmployeeBGA:BG15.62 v v
BGmiles BGEmployee BGB:
v v v
BG41.85 BGmiles
v v
Employee BGC:BG32.67 BGmiles:BGtimes_traveledA BG= BGint(input())
v v v v v v
BGtimes_traveledB BG= BGint(input())
v v v
times_traveledCBG=BGint(input()) v v
BGemployeeA BG= BG15.62 BG#miles
v v v v
BGemployeeB BG= BG41.85 BG#miles
v v v v
BGemployeeC BG= BG32.67 BG#miles
v v v v
distance_traveledA BG= BGtimes_traveledA BG* v v v
BGemployeeA
v BGdistance_traveledB BG= v v
BGtimes_traveledB
v BG* BGemployeeB v v
BGdistance_traveledC
v BG= BGtimes_traveledC BG* v v v
BGemployeeC
v
total_miles_traveled BG= BGdistance_traveledA BG+ BGdistance_traveledB BG+ v v v v v
BGdistance_trav- BGeledC
v v
print('Distance:BG{:.2f} BGmiles'.format(total_miles_traveled))
v v
1
BG/
v
BG12
v
, 2. CreateBGaBGsolutionBGthatBGacceptsBGanBGinputBGidentifyingBGtheBGnameBGofBGa
v v v v v v v v v v v
BGtextBGfile,BGfor BGexample,BG"WordTextFile1.txt".BGEachBGtextBGfileBGcontains
v v v v v v v v v
BGthreeBGrowsBGwithBGoneBGword BGper BGrow. BGUsing BGthe BGopen() BGfunction
v v v v v v v v v v v
BGand BGwrite() BGand BGread() BGmethods, BGinteract BGwith BGthe BGinput BGtext BGfile
v v v v v v v v v v v
BGto BGwrite BGa BGnew BGsentence BGstring BGcomposed BGof BGthe BGthree BGexisting
v v v v v v v v v v v
BGwords BGto BGthe BGend BGof BGthe BGfile BGcontents BGon BGa BGnew BGline. BGOutput
v v v v v v v v v v v v v
BGthe BGnew BGfile BGcontents.: BGfile_name BG= BGinput()
v v v v v v v
with BGopen(file_name, BG'r') BGas BGf:
v v v v
word1 BG= v
BGstr(f.readline()).strip()
v
BGword2 v BG= v
BGstr(f.readline()).strip()
v
BGword3 v BG= v
BGstr(f.readline()).strip()
v
f BG= BGopen(file_name, BG'r')
v v v
BGlinesBG=
v v
BGf.read().splitlines() BGlines
v v
BG= BG' BG'.join(lines)
v v v
BGf.close()
v
print(f'{word1}\n{word2}\n{word3}\n{lines}')
3. Create BGa BGsolution BGthat BGaccepts BGan BGinteger BGinput BGrepresenting BGany
v v v v v v v v v
BGnumber BGof BGounces. BGOutput BGthe BGconverted BGtotal BGnumber BGof BGtons,
v v v v v v v v v v
BGpounds, BGand BGremaining BGounces BGbased BGon BGthe BGinput BGounces BGvalue.
v v v v v v v v v v
BGThere BGare BG16 BGounces BGin BGa BGpound BGand BG2,000 BGpounds BGin BGa BGton.:
v v v v v v v v v v v v v
BGounces_per_pound BG= BG16
v v v
2
BG/
v
BG12
v