IST (Indian Standard Time) is 5 hours 30 minutes ahead of GMT(Greenwich Mean Time). Develop an algorithm and write the Python code to find day and IST, given day and time in GMT. For example, if day is Sunday and time in GMT is 23:05 then in IST is Monday (Next day) and time is 04:35. Check boundary conditions and print 'Invalid input' for wrong input. Write appropriate functions for accomplishing the task.
Use rstrip() to remove extra spaces while reading strings
Input Format
Day
Hours
minutes of time in GMT
Output Format
Day
Hours
minutes of time in IST
Boundary Condition:
All hour > 0 and <24
Minutes > 0 and < 60
Seconds > 0 and <60
Day is Sunday or Monday or Tuesday or Wednesday or Thursday or Friday or Saturday
Input:
Take the input serially as day,hours and minutes.
Processing Involved:
days=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]day=input().rstrip()
hours_min=int(input())*60
minutes=int(input())
total=hours_min+minutes+330
if hours_min>0 and hours_min<24*60 and minutes>0 and minutes<60 and day in days:
if total>=1440:
for i in range(len(days)-1):
if day==days[i]:
print(days[i+1])
break
print(total//60-24)
print(total%60)
else:
print(day)
print(total//60)
print(total%60)
else:
print("Invalid input")
Output:
Display the time in IST
Program:
days=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
day=input().rstrip()
hours_min=int(input())*60
minutes=int(input())
total=hours_min+minutes+330
if hours_min>0 and hours_min<24*60 and minutes>0 and minutes<60 and day in days:
if total>=1440:
for i in range(len(days)-1):
if day==days[i]:
print(days[i+1])
break
print(total//60-24)
print(total%60)
else:
print(day)
print(total//60)
print(total%60)
else:
print("Invalid input")
The code is kinda wrong.. there should be a condition for when the day is sunday otherwise it'll go out of the list as sunday is the last element.
ReplyDeletenever mind... its correct
Delete