Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 8
If you're assuming 24h format input time, you can use hours, minutes = list(map(int, input_time.split(":"))) Now that you have the hours and minutes to work with, everything follows.
2nd May 2020, 4:39 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 3
def convert24(str1): # Checking if last two elements of time # is AM and first two elements are 12 if str1[-2:] == "AM" and str1[:2] == "12": return "00" + str1[2:-2] # remove the AM elif str1[-2:] == "AM": return str1[:-2] # Checking if last two elements of time # is PM and first two elements are 12 elif str1[-2:] == "PM" and str1[:2] == "12": return str1[:-2] else: # add 12 to hours and remove PM return str(int(str1[:2]) + 12) + str1[2:8] # Driver Code print(convert24("08:05:45 PM"))
27th Feb 2022, 5:44 AM
Vaibhav
Vaibhav - avatar
+ 1
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int days = scanner.nextInt(); //your code goes here } }
3rd Jan 2021, 9:19 AM
Haritap Kumar
Haritap Kumar - avatar
0
create three lists: list1 would have numbers that you would consider "morning" list2 would have numbers the you would consider "afternoon" list3 would have numbers the you would consider "evening" myinput = int(input().split(':')[0]) if you need "Noon" and "midnight" specifically....you would need to test for 12 and 00 and amend the lists accordingly. Use if ... in .....: blah blah blah.
2nd May 2020, 4:49 PM
rodwynnejones
rodwynnejones - avatar
0
It works in my mac , maybe you dont have datetime installed
4th May 2020, 2:47 PM
Vishnu
Vishnu - avatar
0
Please stop disliking every little thing I type , instead of commenting on other's fault, atleast i am attempting to solve it . This code works , even on the Sololearn coding for python
4th May 2020, 2:51 PM
Vishnu
Vishnu - avatar
0
The capital thing happened by mistake , On my phone it automatically capitalized it
4th May 2020, 2:55 PM
Vishnu
Vishnu - avatar