Just an input in Python -
i've started learning python. first language, don't harsh on me if easy. can't figure out how solve this. i've programed:
a=input("enter pyramid base size ") h=input ("enter pyramid height size ") p=a*a+2*a*h print (p)
but comes out:
enter pyramid base size 2 enter pyramid height size 2 traceback (most recent call last): file "d:\program files (x86)\python\pyramid.py", line 3, in <module> p=a*a+2*a*h typeerror: can't multiply sequence non-int of type 'str'
the type of input received string equation, numbers needed. can convert input integer or float , math
a = int(a) h = float(h)
now might need check if input can converted number , can like:
try: h = int(h) except valueerror: print 'the input couldnt converted integer'
edit
so, here code should like
a = input("enter pyramid base size ") h = input ("enter pyramid height size ") try: = int(a) h = int(a) p = a*a + 2*a*h print (p) except: valueerror: print 'input cannot converted integer'
Comments
Post a Comment