function - Python issue gave up around 4am -


this question has answer here:

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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -