1) What's the Time Build a Python script that tells you the current time. Create a new script called current_time.py in Jupyter or a text editor. Add a docstring to the script to explain what it does. Import the datetime module. Get the current time using datetime.now(). Print the result, but only if the script is to be executed. *** hint, __name__==__main__ Execute the script in the terminal to check if it prints the time. Import the time into a Python console and check if the console output does not print the time. The output of the terminal should be in this format: HH:MM:SS.SSSSSS In [ ]:

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

(1) What's the Time

Build a Python script that tells you the current time.
  1. Create a new script called current_time.py in Jupyter or a text editor.
  2. Add a docstring to the script to explain what it does.
  3. Import the datetime module.
  4. Get the current time using datetime.now().
  5. Print the result, but only if the script is to be executed. *** hint, __name__==__main__
  6. Execute the script in the terminal to check if it prints the time.
  7. Import the time into a Python console and check if the console output does not print the time.

The output of the terminal should be in this format: HH:MM:SS.SSSSSS

In [ ]:
 

 

(2) Formatting Customer Names

Build a function that displays a customer's name and location if applicable
Suppose that you are building a Customer Relationship Management (CRM) system, and you want to display a user record in the following format: John Smith (California). However, if you don't have a location in your system, you just want to see "John Smith." Create a format_customer() function that takes two required positional arguments, first_ name and last_name, and one optional keyword argument, location. It should return a string in the required format.
  1. Create the customer.py file.
  2. Define the format_customer() function.
  3. Open a Python shell (Or Jupyter Notebook) and import your format_customer() function.
  4. Try running a few examples. The calls should look like this:

    from customer import format_customer
    format_customer('John', 'Smith', location='California')

    and the output should look like this:

    John Smith (California)
In [ ]:
 

 

(3) The Fibonacci Function with an Iteration

Calculate a Fibonacci sequence
You work in an IT firm, and your colleague has realized that being able to quickly compute elements of the Fibonacci sequence will reduce the time taken to execute the testing suite on one of your internal applications. You will use an iterative approach to create a fibonacci_iterative function that returns the nth value in the Fibonacci sequence.
  1. Create a fibonacci.py file.
  2. Define a fibonacci_iterative function that takes a single positional argument representing which number term in the sequence you want to return.
  3. Run the following code:

from fibonacci import fibonacci_iterative
fibonacci_iterative(3)
You should get the following output:
2
Another example to test your code can be as mentioned in the following code snippet:

fibonacci_iterative(10)


You should get the following output:
55

In [ ]:
 

 

(4) The Fibonnaci Function with Recursion

Remake your previous fibonacci program as a recursive function
In [ ]:
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
InputStream
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education