## Python Programming - Price Of Travelling In a Boat

- 12th May, 2019
- 13:01 PM

__ TASK 1 __– calculate the money taken in a day for one boat. The cost of hiring a boat is $20 for one hour or $12 for half an hour. When a boat is hired the payment is added to the money taken for the day. The running total of hours hired that day is updated and the time when the boat must be returned is stored. At the end of the day the money taken and the total hours hired is output. No boat can be hired before 10:00 or returned after 17:00.

__ Program__ -

import random

t= 1

Tmoney = [0,0,0,0,0,0,0,0,0,0]

ReTime = [0,0,0,0,0,0,0,0,0,0]

TrTime =[0,0,0,0,0,0,0,0,0,0]

runningT = 0

RunningH = 0

currentTime = 1111 #time for testing

while t == 1:

currentTime += 1

avail = 0

while currentTime > 1000 and currentTime < 1700:

boatnumber = 9 #boat number 0 to 9(10 boats)

currentTime += 1 #time increment

for i in range(0,10): # caluculating available boats

if ReTime[i] > 0 and ReTime[i] > currentTime: # boats number gets decremented if there is a hired boat

boatnumber -= 1

# hiretype is found using random function currently set to between 1-3

hiretype = random.randint(1,3)

if boatnumber >= 0 and (hiretype == 1 or hiretype ==

__ TASK 2__ – find the next boat available. Extend TASK 1 to work for all 10 rowing boats. Use the data stored for each boat to find out how many boats are available for hire at the current time. If no boats are available show the earliest time that a boat will be available for hire. need program and pseudocode please. python IDLE 2.7.14

__ Program__ -

#if hire type is 1 or 2 the value of these variables are changed to efficiently enter the values into corresponding lists(arrays)

if hiretype == 1:

rTime = currentTime + 60

boatmoney = 20

Time = 60

elif hiretype == 2:

boatmoney = 12

Time = 30

rTime = currentTime + 30

Tmoney[boatnumber] = Tmoney[boatnumber] + boatmoney

TrTime[boatnumber] = TrTime[boatnumber]+ Time

ReTime[boatnumber] =rTime

#if no boats are left shows the earliest time a boat will be available

elif boatnumber < 0:

earliest = 9999

for i in range(0,10):

if ReTime[i] < earliest and ReTime[i] > 0:

earliest = ReTime[i]

print str(earliest) + "earliest", currentTime

highest = 0

mostused = 0

non = 0

dayTmoney = 0

daytotaltime = 0

for i in range(0,10):

dayTmoney += Tmoney[i]

daytotaltime += TrTime[i]

if TrTime[i] > highest:

highest = TrTime[i]

mostused = i + 1

if ReTime[i] == 0:

non += 1

print ("Total money earned on day:" + str(dayTmoney) + "\n"

"Total number of time boats hired:" + str(daytotaltime) +"\n"

"Most used Boat:" + " " + str(mostused) + "\n"

"number of boats not used:" + " " + str(non))

t = 0