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
____ software is rights-protection software used to control the use of a work.
jeka57 [31]
<span>Cyclos is a project of STRO, a leading organisation on monetary innovations. Cyclos offers a complete on-line payment system with additional modules such as e-commerce and communication tools. [ [ The Cyclos platform permits institutions such as local banks and MFI`s to offer banking services that can stimulate local trade and development. Cyclos is also used by many organizations and</span>
3 0
3 years ago
A network technician is asked to redesign an Ethernet network before some new monitoring software is added to each workstation o
mina [271]

Answer: network administrator

Explanation:

8 0
3 years ago
Select the correct answer. Marie uses a browser to visit a blog. How is the blog uniquely identified? A. web page B. website C.
damaskus [11]

Answer:

I belive the answer is E

Explanation:

8 0
2 years ago
Who benefits the most from billing by the second for cloud resources, such as virtual machines?.
scoundrel [369]

Clients that run numerous virtual machines.

<h3>What is a virtual machine?</h3>
  • A virtual machine is the virtualization or emulation of a computer system in computing.
  • The functionality of a physical computer is provided by virtual machines, which are built on computer architectures.
  • Their use may necessitate specialized hardware, software, or a combination of both.
  • Virtual machines' primary function is the simultaneous operation of several operating systems on a single piece of hardware.
  • Without virtualization, running two different physical units would be necessary to run different operating systems, such as Windows and Linux.
  • Through the use of virtualization technologies, virtual machines are made possible.
  • Multiple virtual machines (VMs) can run on a single machine thanks to virtualization, which simulates virtual hardware using software.
  • The real machine is referred to as the host, and any virtual machines running on it as the guests.

To learn more about virtual machines, refer to:

brainly.com/question/27961159

#SPJ4

7 0
1 year ago
Does anyone know the code for the beaded bracelet on codehs? pls i really need help
kvv77 [185]

Answer:

Explanation:

If it has not changed since the last time that i used codehs then the code should be the following

penup()

forward(-100)

right(90)

pendown()

def beaded_bracelet():

circle(10)

penup()

forward(20)

left(10)

pendown()

for i in range(36):

beaded_bracelet()

Which should complete the entire function as intended.

6 0
2 years ago
Other questions:
  • Why are open standards important in the data communications industry?
    5·1 answer
  • What is the differnces between dark and middle ages of computer?​
    9·1 answer
  • Read the scenario below and then answer the
    14·1 answer
  • What does %d, , %c, %s mean and what's their difference?
    12·1 answer
  • When troubleshooting a desktop motherboard, you discover the network port no longer works. What is the best and least expensive
    12·1 answer
  • A form letter can be customized by using different fields in a __________.
    15·2 answers
  • Modify an array's elements Write a for loop that iterates from 1 to numberSamples to double any element's value in dataSamples t
    11·1 answer
  • Adam is writing a program that: 1) has the user guess a number, and 2) tells the user how many guesses it took to get the correc
    9·2 answers
  • Answer for 5,6,7 any one know plz
    8·1 answer
  • When one loop appears inside another, the loop that contains the other loop is called the ____ loop. Group of answer choices ind
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!