Im writing this program that draws a bar graph showing an investment growth. and this error keeps coming up and i cant figure it out. this is the syntax that python keeps telling me.

 Traceback (most recent call last):
  File "C:\Python26\lala.py", line 68, in <module>
    main()
  File "C:\Python26\lala.py", line 47, in main
    height = principal * 0.02
TypeError: unsupported operand type(s) for *: 'NoneType' and 'float' 

and this is my code

#import your graphics
from graphics import *
# graphs future value by displaying it in a graphic window

def main():
#===Draws a graph window    
    win = GraphWin("Future Value",400,300)
    win.setCoords(0.0, 0.0, 3.0, 4.0)
#===displays what the program does and gives user instructions    
    Text(Point(1.5,3.5), "This Plots the growth of a 10-year investment.").draw(win)
    Text(Point(1,3), " Enter the initial Principal:").draw(win)
    Text(Point(1,1), " Enter annualized interest rate:").draw(win)
#===This is the user enter principal data 
    def principal_data():
        input = Entry(Point(2,3), 5)
        input.setText("0.0")
        input.draw(win)
    principal_data()
#===This is the user enter apr date
    def apr_data():
        input = Entry(Point(2,1), 5)
        input.setText("0.0")
        input.draw(win)
    apr_data()
#===draws the calculate button in the graph wun
    button = Text(Point(1.5,2.0), "Calculate")
    button.setFill('red')
    button.draw(win)
    Rectangle(Point(1,1.5), Point(2,2.5)).draw(win)
#===wait for a user mouse click
    win.getMouse()

    principal = principal_data()
    apr = apr_data()

#===create a graphics window with labels on left edge
    win = GraphWin("Investment Growth Chart", 320, 240)
    win.setBackground('white')
#===draws the labels on the left edge    
    Text(Point(20, 230), '0.0k').draw(win)
    Text(Point(20, 180), '2.5k').draw(win)
    Text(Point(20, 130), '5.0k').draw(win)
    Text(Point(20, 80), '7.5k').draw(win)
    Text(Point(20, 30), '10.0k').draw(win)

#===draw bar for initial principal
    height = principal * 0.02
    bar = Rectangle(Point(40, 230), Point(65, 230-height))
    bar.setFill('green')
    bar.setWidth(2)
    bar.draw(win)

#===draw bars for successive years
    for year in range(1,11):
#=======calculate value for the next year
        principal = principal * (1 + apr)
#=======draw bar for this value
        xll = year * 25+40
        height = principal * 0.02
        bar = Rectangle(Point(xll, 230), Point(xll+25, 230-height))
        bar.setFill('green')
        bar.setWidth(2)
        bar.draw(win)

    raw_input("press <enter> to quit")
    win.close()

main()

Edited 3 Years Ago by mike_2000_17: Fixed formatting

height = principal * 0.02
TypeError: unsupported operand type(s) for *: 'NoneType' and 'float'

0.02 is your float and * is your operand. That only leaves principal to be your NoneType. At another point, you are setting principal equal to the return value of a function that doesn't return anything. That's your problem.

height = principal * 0.02
TypeError: unsupported operand type(s) for *: 'NoneType' and 'float'

0.02 is your float and * is your operand. That only leaves principal to be your NoneType. At another point, you are setting principal equal to the return value of a function that doesn't return anything. That's your problem.

Slight correction to your explanation... '*' is your operator and 0.02 and principal are your operands, of type float and NoneType respectively. The remainder I agree with.

When using code tags, you should use [code=python] instead of [code=syntax].

In your code, you do a few things incorrectly. First of all, you shouldn't define functions within other functions. So move those back out a level and take them out of main() . Either that or don't use functions, since neither of those functions actually perform anything at all.

The main problem here is that your principal_data function does not return any values. This means that on the line that reads principal = principal_data , principal is getting assigned a value of None , which is why you're experiencing your fail.

I got that far i changed the principal and apr to input.getText which gets the enter information that the user enter in the text window and puts it into the principal and apr.

now im getting this error.

Traceback (most recent call last):
File "C:\Python26\futuregraph.py", line 65, in <module>
main()
File "C:\Python26\futuregraph.py", line 44, in main
height = principal * 0.02
TypeError: can't multiply sequence by non-int of type 'float'

You've got to post the code where principal comes from. It would seem that principal is a list instead of a number... here look at this example of generating that error:

>>> [ 1,2,3,4] * 0.02
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: can't multiply sequence by non-int of type 'float'
>>>

You've got to post the code where principal comes from. It would seem that principal is a list instead of a number... here look at this example of generating that error:

>>> [ 1,2,3,4] * 0.02
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: can't multiply sequence by non-int of type 'float'
>>>

i figured it out and everything works this is what i needed.

principal = eval(input.getText())
    apr = eval(input.getText())

i appreciate all the help thanks.

This question has already been answered. Start a new discussion instead.