Python Forum
TypeError: unsupported operand type(s) for /: 'str' and 'int'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: unsupported operand type(s) for /: 'str' and 'int'
#1
I am confused to why this doesnt work. Can anyone help?
This is the code
number1 = input("What was the temperature on Monday?")
number2 = input("What was the temperature on Tuesday?")
number3 = input("What was the temperature on Wednesday?")
number4 = input("What was the temperature on Thursday?")
number5 = input("What was the temperature on Friday?")
number6 = input("What was the temperature on Saturday?")
number7 = input("What was the temperature on Sunday?")

total = number1+number2+number3+number4+number5+number6+number7 /7
print("the average temperature was", total, ".")
This is the error
Error:
Traceback (most recent call last): File "C:\Users\Franek\Desktop\Python\Practise of My Skills\temp.py", line 9, in <module> total = number1+number2+number3+number4+number5+number6+number7 /7 TypeError: unsupported operand type(s) for /: 'str' and 'int'
Reply
#2
input will return str you need to convert it to float or int using some built-in function in order to do calculations
then read on operator precedence
cap510 likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  arrays sum list unsupported operand type(s) for +=: 'int' and 'list' DariusCG 7 4,180 Oct-20-2019, 06:24 PM
Last Post: Larz60+
  Resolving unsupported operand type +=: 'int' and 'str' jedmond2 4 6,380 Sep-10-2019, 05:04 PM
Last Post: jedmond2
  TypeError: can't multiply sequence by non-int of type 'complex' FeverDream 2 12,795 Jul-12-2018, 11:08 PM
Last Post: DeaD_EyE
  TypeError: can't multiply sequence by non-int of type 'str' rmpadilla73 4 30,498 May-28-2018, 12:21 AM
Last Post: py_learner
  TypeError: can't multiply sequence by non-int of type 'str' Beatenberg 12 13,730 Oct-10-2017, 10:14 PM
Last Post: Beatenberg
  python!TypeError: can't multiply sequence by non-int of type 'float' shaywune 2 9,522 Sep-24-2016, 04:33 PM
Last Post: shaywune

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020