Getting data type conversion error from user input

143 Views Asked by At

I am having an issue with this code, I have tried changing the data type of just about every part of it. I cant see where the error is. I am aware that this code has probably got a lot of issues. I am very new to programming.

team_1 = input(str("enter the name of team one "))
team_1_avg_goals = input(str("enter the average goals for " + team_1))
team_1_win_percentage = input(str("enter the win rate of " + team_1))
team_2 = input(str("enter the name of team two "))
team_2_avg_goals = input(str("enter the average goals for " + team_2))
team_2_win_percentage = input(str("enter the win percentage for " + team_2 ))

if team_1_win_percentage > team_2_win_percentage:
    print(team_1 + " should win")

else: print(team_2 + " should win")

total_goals = team_2_avg_goals + team_1_avg_goals/2

print(float(total_goals))

Error:

TypeError: unsupported operand type(s) for /: 'str' and 'int'
1

There are 1 best solutions below

2
Or Y On

You have to convert team_1_avg_goals to int. You can either do it on the input line:

team_1_avg_goals = int(input("enter the average goals for " + team_1))
team_2_avg_goals = int(input("enter the average goals for " + team_2))

or here:

total_goals = int(team_2_avg_goals) + int(team_1_avg_goals)/2