Question

PYTHON: Write a code that prints out the current time in hrs:mins:secs. You need to import...

PYTHON: Write a code that prints out the current time in hrs:mins:secs. You need to import the time module (import time). The function time.time() yields the time in seconds since Jan 1, 12 am, 1970; i.e., it yields what is known as the epoch time (GMT). Convert to Pacific Standard time.

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

The answer to the question is given below.


The python code is given below.



#package for datetime and timezone
from datetime import datetime
from pytz import timezone
#getting currnet time
now=datetime.now()
#strftime function formats the string
t=now.strftime("%H:%M:%S")
print("UTC Time: ")
#printing the UTC Time
print(t)
#Changing the timezone from UTC to US/Pacific
now=now.astimezone(timezone('US/Pacific'))
t=now.strftime("%H:%M:%S")
print("Pacific Standard Time:")
print(t)





The screenshot of the running code is given below.





The screenshot of the output is given below.











If the answer helped please upvote it means a lot. For any query please comment.


Add a comment
Know the answer?
Add Answer to:
PYTHON: Write a code that prints out the current time in hrs:mins:secs. You need to import...
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
  • python rephactor 1. Write code that prints the square root of the value in the variable...

    python rephactor 1. Write code that prints the square root of the value in the variable num rounded to 4 decimal places. Assume that num already has a value and that the math module has been imported. 2. Write a function called ordinal_sum that accepts a string argument and returns the sum of the ordinal values of each character in the string. The ordinal value of a character is its numeric Unicode code point in decimal.

  • python 3 please, for these questions you do not need to write the whole code just...

    python 3 please, for these questions you do not need to write the whole code just the expression 1)Write a loop that reads positive integers from standard input, printing out those values that are greater than 100, each on a separate line, The loop terminates when it reads an integer that is not positive. 2) Write a loop that reads positive integers from standard input and that terminates when it reads an integer that is not positive. After the loop...

  • This problem demonstrates the use of import module. The Python programming language has many strengths, but...

    This problem demonstrates the use of import module. The Python programming language has many strengths, but one of its best is the availability to use many existing modules for various tasks, and you do not need to be an experienced computer programmer to start using these modules. We have given you some incomplete code; note that the very first line of that code contains an import statement as follows: import math This statement enables your program to use a math...

  • Write a python code that takes in an number 0-9 and prints out the word of...

    Write a python code that takes in an number 0-9 and prints out the word of the number. For example 1 would print out one. Below is the skeleton of the code that needs to be filled in. def num2string(num): """ Takes as input a number, num, and returns the corresponding name as a string. Examples: num2string(0) returns "zero", num2string(1)returns "one" Assumes that input is an integer ranging from 0 to 9 """ numString = "" ################################### ### FILL IN...

  • Write the python function time to midnight() that takes the name of a file containing multiple...

    Write the python function time to midnight() that takes the name of a file containing multiple lines of text giving time in HH:MM:SS HRS or HH:MM:SS AM or HH:MM:SS PM format one per line. The HRS notation indicates CSE 101 – Summer 2019 Lab Assignment #9 2 that the time has been given in 24-hour time format. Each line tells the current time of the day. The function reads the file line by line and calculates the number of seconds...

  • Write a function to dump the html content, and save it in the same directory of...

    Write a function to dump the html content, and save it in the same directory of your python script. The name of the saved html file should include the current time stamp. I currently have been trying this code. But Repl.it says "ModuleNotFoundError: No module named 'urllib2'". Could someone point out what i am doing wrong and help me include the current time stamp using 'datetime'. The format for the date and time should be YYYY_MM_DD_HH_MM_SS. import urllib2 def webpagedumb(url):...

  • Write a Python Code for a Function: you need to come up with code for shift_char....

    Write a Python Code for a Function: you need to come up with code for shift_char. Write the code in a way in which you can shift the character by writing the number of shifts. Use the ASCII code for this. For example in lie 11, the input for char_to shift is r. U shift it by 1 so it becomes s. below is the function def shift_char(char_to_shift, amount_to_shift): ''' shifts any character by moving it a certain amount on...

  • 1. Pleae write the following code in Python 3. Also, please show all the outputs. ....

    1. Pleae write the following code in Python 3. Also, please show all the outputs. . Write a simple Rectangle class. It should do the following: Accepts length and width as parameters when creating a new instance Has a perimeter method that returns the perimeter of the rectangle Has an area method that returns the area of the rectangle Don't worry about coordinates or negative values, etc. Python provides several modules to allow you to easily extend some of the...

  • 1.  When using a function in the Python standard library, do you need to import the library...

    1.  When using a function in the Python standard library, do you need to import the library into your program before using the function? 2.  How does the walk of a pseudorandom sequence differ from the walk of a truly random sequence? 3.  Is the computer capable of producing a truly random walk in a reasonable amount of time? 4.  Based on your research in the standard library documentation, what is the name of the function that can be used to generate random integer...

  • Solve the code below: CODE: """ Code for handling sessions in our web application """ from bottle import request, response import uuid import json import model import dbsche...

    Solve the code below: CODE: """ Code for handling sessions in our web application """ from bottle import request, response import uuid import json import model import dbschema COOKIE_NAME = 'session' def get_or_create_session(db): """Get the current sessionid either from a cookie in the current request or by creating a new session if none are present. If a new session is created, a cookie is set in the response. Returns the session key (string) """ def add_to_cart(db, itemid, quantity): """Add an...

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