Share your repls and programming experiences

← Back to all posts
UCC Bridge Problem.Final
DozieUzoma (0)

Python program:

from datetime import timedelta

class BridgeProblem:
def init(self, crossTime=1):
self.crossTime = crossTime

def totalCrossingTime(self,totalPerson):
totalPerson = totalPerson*self.crossTime;
if totalPerson==0:
return 0,None;
elif totalPerson>=60:
totalPerson-=1;
return str(timedelta(minutes=totalPerson))[:-3],'hour'
#return (totalPerson//60)+(totalPerson%60),'h'
else:
return totalPerson - 1,'minuts';

def noOfPerson(self):
f = open("gNames.csv", "r")
names = f.read()
f.close()
name = names.split(" ")
return len(name)

def get_BridgeCrossingTime(self): #(in minuts)
self.crossTime = input("Enter the per pair bridge crossing time ==> ")

bp = BridgeProblem() #default crossTime 1 minutes
total_person = bp.noOfPerson()
print('number of person is ',total_person)
print('number of person pair is ',total_person-1)
totaltime,timeplace = bp.totalCrossingTime(total_person)
print('total time to cross all person is ',totaltime,timeplace)