Import math, from math import ceil
Why does this code work houses = int(input()) import math print(int(math.ceil((2/houses)*100))) And not this one? houses = int(input()) from math import ceil print(int(math.ceil((2/houses))*100)) Am I missing something in the importing part?
First import...... Then write the code For ex : Import ...... //Your code
In the second case. Don't type 'math.ceil' Try only 'ceil'. You are not importing the whole math module in the second case, you are just taking its one part.
See, whenever you import a module, you actually avail your program to use the various classes and functions of the file/s corresponding to that module by accessing them in the following manner: module.function() or module.class() But when you use from.....import....., you are not importing that module actually and just importing some of its functions or classes (as mentioned by you after 'import'). That means, instead of availing your program to use the whole module, you're ONLY ALLOWING ONE OR SOME OF ITS FUNCTIONS/CLASSES. Therefore, you need to use them directly, without mentioning the name of the module: function() or class() Example: import math or from math import ceil, floor math.ceil() ceil() math.floor() floor()