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