Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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
47,913 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
47,913 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,546 Points

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