Tell us what’s happening:
my code works well on pycharm but keeps giving me errors on repl, please what am i missing…
here is my repl.io link
https://repl.it/@OjimaojoBethelB/boilerplate-time-calculator-1#time_calculator.py
Your code so far
def add_time(start, duration, day='any1'):
# getting the hour and min.
startHour = int(start.split(":")[0])
startMin = int(start.split(":")[1].split(" ")[0])
addTime = duration.split(':')
durationHour = addTime[0]
durationMin = addTime[1]
amPm = ''
if 'PM' in start:
startHour += 12
daysNumber = 0
newHour = int(startHour) + int(durationHour)
if newHour > 24:
if newHour % 24 == 0:
daysNumber = newHour / 24
newHour = 00
else:
daysNumber = newHour // 24
remainingHours = newHour % 24
newHour = remainingHours
if newHour < 12:
amPm = 'AM'
else:
amPm = 'PM'
newHour -= 12
tempMin = int(startMin) + int(durationMin)
if tempMin > 60:
newMin = tempMin - 60
newHour += 1
else:
newMin = tempMin
hour = newHour
if day != 'any1':
if daysNumber < 7:
weekdays = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday", "monday", "tuesday",
"wednesday", "thursday", "friday", "saturday"]
for days in weekdays:
if days == day.lower():
tempDay = weekdays.index(day)
newDay = weekdays[tempDay + daysNumber].capitalize()
new_time = F"{hour}:{newMin} {amPm} {newDay}"
else:
if daysNumber < 1:
new_time = F"{hour}:{newMin} {amPm}"
if daysNumber == 1:
new_time = F"{hour}:{newMin} {amPm} (next day)"
if daysNumber >= 7:
new_time = F"{hour}:{newMin} {amPm} ({daysNumber} days later)"
return new_time
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36
.
Challenge: Time Calculator
Link to the challenge: