Question

In (11): def convert time time in seconds) <Fill in the docstring for this function 0 # <Add your code below. Note that the r

0 0
Add a comment Improve this question Transcribed image text
Answer #1


Concept:

here is the python code for the convert time and the exact time like 1:07 or 2:07 for checking the values… we use simple maths like 1hour=3600 seconds and modulus operator to achieve this task

We use if else to check the condition and assign the appropriate values.


'''this is the function here below that convert_time

from the seconds to the hours minutes and seconds using

modulus and division operator.'''

def convert_time(time_in_seconds):

    

    '''we get the hours since 3600 seconds =1 hours '''

    hours=int(time_in_seconds/3600)

    if(hours==12):

        designation="noon"

        

    elif(hours>12):

        designation="PM"

        

    else:

        designation="AM"

    '''provide the designation as above...'''

    

    

    time_in_seconds=time_in_seconds%3600

    '''similarly we have 60 seconds =1 minutes so division will give

    minutes and modulus will give us back left over seconds'''

    minutes=int(time_in_seconds/60)

    seconds=int(time_in_seconds%60)

    

    '''print the time as below...'''

    return "{:02d}:{:02d}:{:02d}{}".format(hours,minutes,seconds,designation)

    

'''call the below functions.'''    

print(convert_time(2*60*60+7))

print(convert_time(7))

print(convert_time(15*60*60+27*60+9))

print(convert_time(12*60*60))


def timer(time_in_seconds):

    

    hours=int(time_in_seconds/3600)

    time_in_seconds=time_in_seconds%3600

    

    minutes=int(time_in_seconds/60)

    seconds=int(time_in_seconds%60)

    

    '''first find the time in minutes seconds and hours using the

    same method as above defined. then we take the time after midnight.

    like after 1 oclock in midnight so we take the condition at 7 minutes

    and hours after midnight at 0 seconds..........'''

    if( hours>=1 and minutes==7 and seconds==0):

        return True

        

    else:

        return False

    '''otherwise return False..'''


'''in the testing cases check in the loop and then

for True values

and print the required seconds.. like 4020 aka 1:07 pm and so on'''

for time_in_seconds in range(24*60*60):

    

    if( timer(time_in_seconds) ):

        print("time to do my task {}".format(time_in_seconds) )



OUTPUT:

02:00:07AM

00:00:07AM

15:27:09PM

12:00:00noon

time to do my task 4020

time to do my task 7620

time to do my task 11220

time to do my task 14820

time to do my task 18420

time to do my task 22020

time to do my task 25620

time to do my task 29220

time to do my task 32820

time to do my task 36420

time to do my task 40020

time to do my task 43620

time to do my task 47220

time to do my task 50820

time to do my task 54420

time to do my task 58020

time to do my task 61620

time to do my task 65220

time to do my task 68820

time to do my task 72420

time to do my task 76020

time to do my task 79620

time to do my task 83220


    54 55 56 in the testing cases check in the loop and then 57 for True values 58 and print the required seconds.. like 4020 a1 2 lthis is the function here below that convert_time 3 from the seconds to the hours minutes and seconds using 4 modulus28 29 call the below functions. 30 print(convert_time ( 2*60*60+7)) 31 print(convert_time(7)) 32 print(convert_time ( 15*641 minutes=int(time_in_seconds/60) 42 seconds=int(time_in_seconds %60) 43 44 first find the time in minutes seconds and hou

        

    

        NOTE :

IN CASE OF ANY QUERY PLEASE ASK IN THE COMMENT SECTION

THANK YOU

SUPPORT WITH YOUR UPVOTE

KEEP CHEGGING

Add a comment
Know the answer?
Add Answer to:
In (11): def convert time time in seconds) <Fill in the docstring for this function 0...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In python using a def main() function, Write a function that will print a hello message,...

    In python using a def main() function, Write a function that will print a hello message, then ask a user to enter a number of inches (should be an integer), and then convert the value from inches to feet. This program should not accept a negative number of inches as an input. The result should be rounded to 2 decimal places(using the round function) and printed out on the screen in a format similar to the example run. Use a...

  • i need #6 but i believe #6 function needs to call #5 function. I would like...

    i need #6 but i believe #6 function needs to call #5 function. I would like this in C language, and have no pointers, arrays or strings (on function calling and parameters). Thanks! I have attached the other functions that you might need to call for function 6 1. Write and test a function called is_multiple_of that takes a integer n1, integer n2 and determines whether the second argument (n2) is a multiple of the first argument (n1). The function...

  • HINT: USE def count_letters function: DO NOT use Length Function!!!!!!!!!!!!!!!!!!!!!!!! use string format to display percentage....

    HINT: USE def count_letters function: DO NOT use Length Function!!!!!!!!!!!!!!!!!!!!!!!! use string format to display percentage. "{:.1f}".format DO NOT USE ROUND PYTHON: Develop a program that asks the user to enter a text. The program should analyze the text and print out unique letters, in alphabetical order, with the percentage information of each letter. Case should be ignored. Write a function to analyze the text string. No global variables are used in the function. Function parameters must be used. Hint:...

  • Time.cpp: #include "Time.h" #include <iostream> using namespace std; Time::Time(string time) {    hours = 0;   ...

    Time.cpp: #include "Time.h" #include <iostream> using namespace std; Time::Time(string time) {    hours = 0;    minutes = 0;    isAfternoon = false;    //check to make sure there are 5 characters    if (//condition to check if length of string is wrong)    {        cout << "You must enter a valid military time in the format 00:00" << endl;    }    else    {        //check to make sure the colon is in the correct...

  • Using Python a) Add a function to the Projectle class below so it can print out...

    Using Python a) Add a function to the Projectle class below so it can print out the current status seconds, position, and total velocity (not the x,y components) It should work as ilustrated bekow, so you can directly print the instance of the Projectie object b) If the projectile reaches ts maximum height automatically print a message with the current time and height. Make sure this only prints once if time is updated continucusty You do not need to calculate...

  • Need some assistance of reorganizing this whole program. I have the right code for everything I...

    Need some assistance of reorganizing this whole program. I have the right code for everything I just need help on putting all the codes in the right spot so it can come out to the correct output. output is supposed to look like this: 1 \\ user inputs choice to convert 12 to 24 8 \\ user inputs 8 for hours 30 \\ user inputs 30 for minutes 20 \\ user inputs 20 for seconds AM \\ user inputs AM...

  • Write a complete C program for an automatic teller machine that dispenses money. The user should...

    Write a complete C program for an automatic teller machine that dispenses money. The user should enter the amount desired (a multiple of 10 dollars) and the machine dispenses this amount using the least number of bills. The bills dispenses are 50s, 20s, and 10s. Write a function that determines how many of each kind of bill to dispense. When writing your function begin to pass your variables using pointers (or rather "pointing" to your data". Use the TimeSpace program...

  • Lab Exercise #11 Assignment Overview You will work with a partner on this exercise during your la...

    help with cse problem Lab Exercise #11 Assignment Overview You will work with a partner on this exercise during your lab session. Two people should work at one computer. Occasionally switch the person who is typing. Talk to each other about what you are doing and why so that both of you understand each step Part A: Class Date . Download the files for this laboratory exercise, then run the Python shell and enter the following commands: >>>import date >>help(...

  • HI C PROGRAMMING COULD YOU,, Rewrite the program to have it display the time on the...

    HI C PROGRAMMING COULD YOU,, Rewrite the program to have it display the time on the second line of the display, using the HH:MM:SS format. Use the 24-hour format for the hours, in other words, have the time go from 00:00:00 to 23:59:59. #include<LiquidCrystal.h> LiquidCrystal LcdDriver(11, 9, 5, 6, 7, 8); int minutes = 27; //These global integers keep the value of the clock int sec = 10; int hr = 10; const long interval = 1000; //This interval is...

  • def st_petersburg_lottery(): print("###### St. Petersburg Lottery ######") print("Instructions:") print("You will select any number greater than 0.")...

    def st_petersburg_lottery(): print("###### St. Petersburg Lottery ######") print("Instructions:") print("You will select any number greater than 0.") print("Up to the number of times you chose, we will randomly choose 0 or 1.") print("If a 1 is chosen before the last drawing, then you lose.") print("If a 1 does not appear at all, then you lose.") print("You win if 1 is chosen for the first time exactly on the last drawing.") print() def first_to_a_word(): print("###### First to a Word ######") print("Instructions:") print("You...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT