0

Non integer of type?

Trying to find the average of a group of numbers. Googled solutions (which looks nice) but get the following error message: Traceback (most recent call last): File "..\Playground\", line 4, in <module> print('Percent of X: '+str(X*Z)+'%') TypeError: can't multiply sequence by non-int of type What do they mean by "non integer of type"? X = input() Y = input() Z = 100/(int(X)+int(Y)) print('Percent of X: '+str(X*Z)+'%') print('Percent of Y: '+str(Y*Z)+'%') https://code.sololearn.com/c93cQeuPa5j0/#py

19th Sep 2019, 8:47 PM
tristach605
tristach605 - avatar
2 Antworten
+ 2
input() always returns a string. You need to convert these to floats (or integers) to do mathematical operations. X = float(input()) Y = float(input()) Z = 100/(int(X)+int(Y)) print('Percent of X: '+str(X*Z)+'%') print('Percent of Y: '+str(Y*Z)+'%')
19th Sep 2019, 8:54 PM
Russ
Russ - avatar
0
Thanks, Russ!
20th Sep 2019, 9:34 PM
tristach605
tristach605 - avatar