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
Why do you think flowers are a popular topic for macro photography? Do you think you’d like to photograph flowers?
Helen [10]

Why do you think flowers are a popular topic for macro photography?

Macro photography is the part of photography that focuses on taking pictures of very small objects (or small parts of larger objects).  Popular subjects are insects, flowers and small mechanical parts.

Flowers are a very popular subject because they always have lots of interesting details no matter how close you zoom in, like insects.  Flowers however tend to be easier to photograph because they move a lot less than insects.

Do you think you’d like to photograph flowers?

Yes, because it's a new way to look at them.

6 0
3 years ago
6. According to camp policy, staff members need to be at least 23 years old to transport students. Dean now wants to determine h
Kamila [148]

Answer:

This seems to be related to MS Excel, here we will discuss the related formula:

<u>=IF(VLOOKUP("Adam Moriarty",$B$3:$C$5,2)>23,"Yes","No")</u>

the name can also be written in adjacent to J2 cell i.e. I2 and its reference to be used in vlookup primary key as follows:

<u>=IF(VLOOKUP(I2,$B$3:$C$5,2)>23,"Yes","No")</u>

Explanation:

We have used simple IF function combined with VLOOKUP function to reference this formula to the table of names and ages of the members (here the table is $B$3:$C$5 and ages are mentioned in 2nd column of the table)

please find attached screenshot for clarification

6 0
3 years ago
What does a mother board in a computer do?
IRINA_888 [86]

The motherboard is the central component of a computer. Without it, the computer would not work. The mother board is sometimes called "the heart of the computer" because it allows thinks to function properly.

The motherboard of the computer is the part that holds the system memory and audio. It's a printed circuit board.

4 0
3 years ago
Electricity from has enough energy to stop your what?
Ne4ueva [31]

Can I get some options?


The second one is most likely "Heart", but the first one could be a number of things, unless this just pasted incorrectly.'


5 0
4 years ago
1) These are operators that add and subtract one from their operands.
adoni [48]

Answer:

1) B (++ and --)

2) A (1 2 3 4 5)

Explanation:

In the first question, the operators ++ and -- are used in almost all programming languages for adding  and subtracting  1 respectively from an operand.

In the second question using a while statement the numbers 1-5 is printed out because the variable n=1 is increased by 1 after each iteration.

7 0
3 years ago
Other questions:
  • What is the only true way to wipe out every possibility of the virus?
    11·1 answer
  • To view the results of a saved query, right-click the query in the Navigation Pane and click ____ on the shortcut menu.
    7·1 answer
  • What does "CYBER-COCKROACH" mean??
    15·1 answer
  • 3. The invention of the transistor was important to the development of computers because it
    5·1 answer
  • Once you record your audio and click ok to save it what happens to the recording?
    9·1 answer
  • What function returns a line and moves the file pointer to the next line?
    9·1 answer
  • 3.4 lesson practice quiz edhesive
    11·1 answer
  • Which of the following is not a natural resource
    11·2 answers
  • Please help me please
    8·1 answer
  • Which of the following activities do not involve Information technology​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!