-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtime.py
More file actions
60 lines (55 loc) · 3.38 KB
/
Copy pathtime.py
File metadata and controls
60 lines (55 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from rich.panel import Panel
from rich.console import Console
rc=Console()
#12 Hr to 24 Hr Time Converter
try:
time=input("Enter the time(in 12 hour clock ex-> 1:39 pm):")
a=time.split(" ")
ampm=a[len(a)-1]
t=a[0].split(":")
hr=t[0]
mi=t[1]
m1=hr+":"+mi+" "+ampm
if int(hr)<12 and int(mi)<=60 and hr>0 and ampm=="am":
sorted=str(hr)+":"+str(mi)
rc.print(Panel(f"[yellow]12 hour Time:-[/yellow][cyan] {m1}[/cyan]\n[yellow]24 hour Time:-[/yellow][cyan] {sorted}[/cyan]",title="[blue]12 hr to 24 hr Time Converter[/blue]"))
elif int(hr)<12 and int(mi)<=60 and hr>0 and ampm=="pm":
sorted=str(int(hr)+12)+":"+str(mi)
rc.print(Panel(f"[yellow]12 hour Time:-[/yellow][cyan] {m1}[/cyan]\n[yellow]24 hour Time:-[/yellow][cyan] {sorted}[/cyan]",title="[blue]12 hr to 24 hr Time Converter[/blue]"))
elif int(hr)==12 and int(mi)<=60 and hr>0 and ampm=="pm":
sorted=str(hr)+":"+str(mi)
rc.print(Panel(f"[yellow]12 hour Time:-[/yellow][cyan] {m1}[/cyan]\n[yellow]24 hour Time:-[/yellow][cyan] {sorted}[/cyan]",title="[blue]12 hr to 24 hr Time Converter[/blue]"))
elif int(hr)==12 and int(mi)<=60 and hr>0 and ampm=="am":
sorted=str(int(hr)-12)+":"+str(mi)
rc.print(Panel(f"[yellow]12 hour Time:-[/yellow][cyan] {m1}[/cyan]\n[yellow]24 hour Time:-[/yellow][cyan] {sorted}[/cyan]",title="[blue]12 hr to 24 hr Time Converter[/blue]"))
else:
rc.print(Panel("[red]Invalid Inputs[/red]",title="[blue]12 hr to 24 hr Time Converter[/blue]"))
except:
rc.print(Panel("[red]Invalid Inputs[/red]",title="[blue]12 hr to 24 hr Time Converter[/blue]"))
#24 Hr to 12 Hr Converter
try:
time=input("Enter the time(in 24 hour clock ex-> 21:3):")
t=time.split(':')
hr=int(t[0])
mi=int(t[1])
m1=str(hr)+":"+str(mi)
if hr<12 and hr>0 and mi>=0 and mi<=60:
sorted=str(hr)+":"+str(mi)+" am"
rc.print(Panel(f"[yellow]24 hour Time:-[/yellow][cyan] {m1}[/cyan]\n[yellow]12 hour Time:-[/yellow][cyan] {sorted}[/cyan]",title="[blue]12 hr to 24 hr Time Converter[/blue]"))
elif hr>12 and hr<24 and mi>=0 and mi<=60:
sorted=str(int(hr)-int(12))+":"+str(mi)+" pm"
rc.print(Panel(f"[yellow]24 hour Time:-[/yellow][cyan] {m1}[/cyan]\n[yellow]12 hour Time:-[/yellow][cyan] {sorted}[/cyan]",title="[blue]12 hr to 24 hr Time Converter[/blue]"))
elif hr==0 and mi>=0 and mi<=60:
sorted="12"+":"+str(mi)+" am"
rc.print(Panel(f"[yellow]24 hour Time:-[/yellow][cyan] {m1}[/cyan]\n[yellow]12 hour Time:-[/yellow][cyan] {sorted}[/cyan]",title="[blue]12 hr to 24 hr Time Converter[/blue]"))
elif hr==12 and mi>=0 and mi<=60:
sorted=str(hr)+":"+str(mi)+" pm"
rc.print(Panel(f"[yellow]24 hour Time:-[/yellow][cyan] {m1}[/cyan]\n[yellow]12 hour Time:-[/yellow][cyan] {sorted}[/cyan]",title="[blue]12 hr to 24 hr Time Converter[/blue]"))
elif hr==24 and mi==0:
sorted="12"+":"+str(mi)+" am"
rc.print(Panel(f"[yellow]24 hour Time:-[/yellow][cyan] {m1}[/cyan]\n[yellow]12 hour Time:-[/yellow][cyan] {sorted}[/cyan]",title="[blue]12 hr to 24 hr Time Converter[/blue]"))
else:
rc.print(Panel("[red]Invalid Inputs[/red]",title="[blue]24 hr to 12 hr Time Converter[/blue]"))
except:
rc.print(Panel("[red]Invalid Inputs[/red]",title="[blue]24 hr to 12 hr Time Converter[/blue]"))
#Sam Tech Op lel :-)