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
Privacy, anonymity, and freedom of expression are all interrelated.
Andre45 [30]

Answer:

Criminals (terrorists).

Explanation:

6 0
3 years ago
ASAP BRAINLIEST!!!
Hoochie [10]

Answer:

none

Explanation:

6 0
3 years ago
Text,Audio and graphic is entered into the computer using
Inessa [10]

Answer:

I think it's input, not sure tho

8 0
3 years ago
Write a cout statement that prints the value of a conditional expression. The conditional expression should determine whether th
zheka24 [161]

Answer:

#include <iostream>

using namespace std:

int main (){

int score=0;

cin>>score;

if (score==100)

cout << "Perfect";

else

cout <<"Nice Try";

return 0;

}

Explanation:

7 0
3 years ago
When an object is selected, it is surrounded by ________, which allow you to change the size of the object.?
boyakko [2]
Matter. because matter surrounds us all and helps us move and change. 
6 0
3 years ago
Other questions:
  • A virus has attacked your hard drive and now when you start up Windows, instead of seeing a Windows desktop, the system freezes
    9·2 answers
  • What is meant by encapsulating semaphores? Bring out the need for it
    12·1 answer
  • When public relations professionals make provocative statements in newsgroups to get people to visit an organization's website o
    10·1 answer
  • Samuel wanted to paste the value and the formula attached from cell B6 to cell F16. Which methods will work? Check all that appl
    5·2 answers
  • Careers in information technology deal with
    12·2 answers
  • What type of account provides the same functions as managed service accounts but can be managed across multiple servers as in a
    8·1 answer
  • True or False
    11·1 answer
  • What does BGP use by default to calculate the best route?
    15·1 answer
  • Write the definition of a function that evaluates three double numbers and returns true if the floor of the product of the first
    8·1 answer
  • You are the security analyst for your organization and have discovered evidence that someone is attempting to brute-force the ro
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!