Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics Functions and Looping Returning Values

Michael Sothan
Michael Sothan
8,048 Points

Can't import math module

I'm trying to use math.ceil() within my code but i'm receiving an error "AttributeError: module 'math' has no attribute 'ceil'" I've already added the "import math" line to the top of the file. It seems like the math module is not importing to my workspace. Any suggestion?

Thanks

Michael Hulet
Michael Hulet
Treehouse Moderator 47,831 Points

Can you post your code here, particularly the lines where you import. the math module and try to call the ceil function?

1 Answer

Michael Sothan
Michael Sothan
8,048 Points

Thanks Michael. Code below:

import math

def split_bill(total, number_of_people):
  cost_per_person = (total / number_of_people)
  return cost_per_person

people = int(input("How many people were you? "))
check_amount = float(input("How much was the bill? "))

amount_due = math.ceil(split_bill(check_amount, people))

print("Each person should pay ${} ...dude".format(amount_due))
Michael Hulet
Michael Hulet
Treehouse Moderator 47,831 Points

Hmm, something definitely seems wonky, then, because that works on my machine. Do you happen to have a file called math.py in the same folder as this file?

Eric M
Eric M
11,507 Points

Are you trying this in the Treehouse workspace or on your computer?