Lowest price ever! Learn Generative AI for 48% less!
Get my discount+ 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.
+ 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"))
+ 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
}
}
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.
0
It works in my mac , maybe you dont have datetime installed
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
0
The capital thing happened by mistake , On my phone it automatically capitalized it