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]
3 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]3 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
Do you think privacy policies are effective in social networking sites?
Kamila [148]

Answer:

When that information gets posted online, it is no longer private, and may end up falling into wrong hands. Even if you have put in place the highest possible security measures, some of your friends, colleagues and companies you interact with on social media, can end up leaking your personal information.

4 0
3 years ago
True or false you have no control over who views your social network information
cestrela7 [59]
<span>This statement is false. Privacy is a very high-stakes concern for many social networks, who have gone to great lengths to put in place certain restrictions, such as the ability to make ones profile private or hide a profile from certain individuals.</span>
4 0
3 years ago
Is a multiuser computer system that runs a network operating system?
jasenka [17]
No . A multiuser computer system does not run a network operating system
8 0
3 years ago
What are cartesian robot?
ser-zykov [4K]
Cartesian robots are industrial robots which have three principal axes of control, they’re linear and they’re right angles to each other. There are three sliding joints correspond to moving the wrist up and down, in and out, back and forth. There is many other advantages as well
4 0
3 years ago
Does anyone know the answer to this question
koban [17]
The answer would be D) because they want the best of the best
7 0
3 years ago
Other questions:
  • Generally speaking, mobile sites are good for acquiring new customers and inspiring new relationships while mobile apps are good
    6·1 answer
  • Okay so, not really a question but whatever it’s been bothering me.
    9·2 answers
  • Describe an ergonomic consideration for your body while working for long periods in front of a monitor or computer screen?
    14·1 answer
  • If an engine has four cylinders and a total of 16 valves, how many valves would each cylinder have?
    7·1 answer
  • Microsoft's
    8·1 answer
  • Methods that require you to use an object to call them are called ____ methods.1. accessor
    7·1 answer
  • If you need to add more data between column A and column B, you should _____. click in column A and paste a column click anywher
    12·1 answer
  • The part of a rocket engine that allows the combustion gases and flames to leave the rocket engine is the
    14·1 answer
  • If you see these REPORT.
    14·2 answers
  • _____ is a higher-level, object-oriented application interface used to access remote database servers
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!