function - Python issue gave up around 4am -
this question has answer here:
- how can read inputs integers? 14 answers
program requests 4 number (integer or floating-point) user. program should compute average first 3 numbers , compare average fourth. if equal, program should print 'equal' on screen.
import math x1 = input('enter first number: ') x2 = input('enter second number: ') x3 = input('enter third number: ') x4 = input('enter fourth number: ') if ( x4 == (x1 + x2 + x3) / 3): print('equal')
error message:
if ( x4 == (x1 + x2 + x3) / 3): typeerror: unsupported operand type(s) /: 'str' , 'int'"
second error message after trying convert int:
x1 = int(input('enter first number: ')) valueerror: invalid literal int() base 10:
you using mathematical operands on strings. here fix:
import math x1 = int(input('enter first number: ')) x2 = int(input('enter second number: ')) x3 = int(input('enter third number: ')) x4 = int(input('enter fourth number: ')) if ( x4 == (x1 + x2 + x3) / 3): print('equal')
you have cast strings int.
Comments
Post a Comment