Import Styles: Module vs from vs as

Easy ⏱ 8 min 79% acceptance ★★★★★ 4.7
Demonstrate the three import forms in one snippet: (1) import math then math.sqrt, (2) from math import floor used bare, (3) import math as m with m.ceil. Write three_ways(x) returning the tuple (math.sqrt(x), floor(x), m.ceil(x)) with all three imports present.

Examples

Example 1
Input
three_ways(6.5)
Output
(2.5495097567963922, 6, 7)
Explanation

sqrt via module access, floor via from-import, ceil via alias.

Constraints

  • All three import statements must appear.
  • Each style must actually be used.

Topics

Modules & Packagesimport forms

Companies

WiproHCLTechCognizant

Hints

Hint 1

Multiple imports of the same module are cheap — it is cached.

Hint 2

The alias m and name math refer to the same module object.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.