1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
spayn [35]
2 years ago
8

I need to write a really simple python program to solve this issue. I have most of the program written but, when I run the secon

d example, the result is incorrect. Examples 1 and 3 work just fine.
Write a program to calculate the number of seconds since midnight. For example, suppose the time is 1:02:05 AM. Since there are 3600 seconds per hour and 60 seconds per minutes, it has been 3725 seconds since midnight (3600 * 1 + 2 * 60 + 5 = 3725). The program asks the user to enter 4 pieces of information: hour, minute, second, and AM/PM. The program will calculate and display the number of seconds since midnight. [Hint: be very careful when the hour is 12].

Examples for testing code:

Enter hour: 1 Enter minute: 2 Enter second: 5 Enter AM or PM: AM Seconds since midnight: 3725

Enter hour: 11 Enter minute: 58 Enter second: 59 Enter AM or PM: PM Seconds since midnight: 86339

Enter hour: 12 Enter minute: 7 Enter second: 20 Enter AM or PM: AM Seconds since midnight: 440

Here is the code that I have written: As I have said, It should be a simple program.

Thank you in advance for your help!!!!


hour = float(input("Enter hour:"))
minute = float(input("Enter minute:"))
second = float(input("Enter second:"))
am_pm = input ("Enter AM or PM:")
if am_pm == "am" and hour == 12:
hour = 0
seconds_since_midnight = ((3600 * hour) +(minute *60) + second)
print("Seconds since midnight:", seconds_since_midnight)
Computers and Technology
1 answer:
denis-greek [22]2 years ago
4 0

Answer:

hour = float(input("Enter hour:"))

minute = float(input("Enter minute:"))

second = float(input("Enter second:"))

am_pm = input ("Enter AM or PM:")

if am_pm == "AM":

   if hour == 12:

       hour = 0

   seconds_since_midnight = ((3600 * hour) +(minute *60) + second)

elif am_pm == "PM":

   seconds_since_midnight = ((3600 * (hour+12)) +(minute *60) + second)

print("Seconds since midnight:", int(seconds_since_midnight))

Explanation:

The point here is when PM is chosen, you need to add 12 to the hour. I added <em>elif</em>  part to satisfy this. Moreover, since the output is in integer format, you may need to apply type casting for <em>seconds_since_midnight</em> variable.

You might be interested in
Match the personality traits with their description
Crank

Believing in your capabilities and demonstrating confidence in the tasks you perform - Self Esteem

Being loyal, sincere, and trustworthy in your job - Honesty

Being friendly and communicating enthusiastically with co workers - Sociability

Being accountable for your actions - Responsibility

Hope this helped!

~Just a girl in love with Shawn Mendes

7 0
3 years ago
Read 2 more answers
Why a management-focused program provides a more appropriate learning path for you than a program based heavily on technical con
AlekseyPX
The program makes more money
3 0
3 years ago
This is a glitch ? 


 










































mixer [17]

Answer:

I think no...Brainly might not allow unique text's.

8 0
3 years ago
Off topic lol but does anyone know of a free app that lets you track family and friends like their location? Thx
prohojiy [21]

Answer:Life360 has a free version and a paid

Explanation:Life360 let’s you track family by placing them in “family circles” and then allows you to track their location once they accept the invite to the circle, you May also place specific areas that it will alert them entering and exiting.

4 0
3 years ago
Read 2 more answers
Variables make it easier to do what?
defon
<span>D. Make changes to your code
Variables allow the ability to easily substitute numbers for other numbers.
</span>
8 0
3 years ago
Other questions:
  • What is the term for the error caused when one end of an unshielded twisted-pair (UTP) cable is terminated in the T568A configur
    6·1 answer
  • Suppose there are two links between a source and a destination. The first link has transmission rate 100 Mbps and the second lin
    12·1 answer
  • You would like to put the data in order by product number. What should you do?
    15·1 answer
  • !WILL MARK BRAINLIEST!
    8·1 answer
  • A group of students is performing an investigation to measure how much liquid water is produced from a 10 L sample of snow. What
    6·1 answer
  • Write a program that first reads in the name of an input file and then reads the input file using the file.readlines() method. T
    11·1 answer
  • Using a text editor, create a file that contains a list of at least 15 six-digit account numbers. Read in each account number an
    7·1 answer
  • The computer components that enables a computer to send and receive data, instructions or information from one or more computers
    13·1 answer
  • The objective of this task is to use Scapy to estimate the distance, in terms of number of routers, between your VM and a select
    7·2 answers
  • How many dlcs in total were in each black ops game (including dlc weapons) answer for 25 whole points
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!