[Solved] Error from division operator


The code you had was:

Traceback (most recent call last):
  File "C:/Users/Leb/Desktop/Python/test.py", line 14, in <module>
    dayspermonth = (hourspermonth) / (hourspernight) * 24
TypeError: unsupported operand type(s) for /: 'NoneType' and 'int'

That’s because on line 12 you put hourspermonth = print("you also sleep", hourspermonth,"hours per month"). Take out hourspermonth from your script. Same with last line.

#sleep calculator, user enters there hours slept over a nicght and the   program
#will work out different facts about there sleaping
print("Welcome to the sleep calculator, all you have to do is answer one question...")
hourspernight = int(input("how many hours per night do you sleep?"))
#variable for the hours per week slept
hoursperweek = hourspernight * 7
#telling the user how many hours er week they sleep
print ("you sleep", hoursperweek,"hours per week")
#variable for how many hours per month they sleep
hourspermonth = float(hoursperweek * 4.35)
#teling the user how namy hours per month they sleep
print("you also sleep", hourspermonth,"hours per month")
#ISSUE, this is the variable that python has a problem with, and I'm not sure why
dayspermonth = (hourspermonth) / (hourspernight) * 24
#telling the user how many days per month they sleep (this bits ok... I think)
print("you sleep for",dayspermonth,"days per month aswell!")

Side note: In python it’s better if you make sense of your variables. Instead of using hourspernight use hours_per_night or even smaller hrs_night then next to it add comments if you need. Make it more presentable overall.

Edit

Change line 12 to:

print("you also sleep", "{0:.2f}".format(hourspermonth),"hours per month")

This will fix your format issue and make it 2 digits after the decimal point

Edit 2

Change line 14 and 16 to:

dayspermonth = (hourspermonth) / 24
...
print("you sleep for","{0:.2f}".format(dayspermonth),"days per month aswell!")

5

solved Error from division operator