Python Forum
Cant multiply sequence by non-int type 'str'
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cant multiply sequence by non-int type 'str'
#1
trying to make a script that solves a simple math problem (example x(2)+4x-2=0)
however i get this error and can't find why i get it,i went from python 2 to 3 and had to add () to the print commands ,even if i change input to raw_input and try it in python 2 i get the same error
here is my code


import math
print  ("Ax*2+Bx+C=0")
print ("what is your A?")
a = input('my a is: ')
print ("what is your B?")
b = input('my b is: ')
print ("what is your C?")
c = input('my c is: ')
print ("calculating")
b2 = b*b
d = b2-4*a*c
sqd = math.sqrt(d)
x1a = -b+sqd
x2a = -b-sqd
ax2 = a*2
x1 = x1a/ax2
x2 = x2a/ax2
print ("your X1 is ") + x1 +  ("your X2 is") + x2
print ("your discriminant is") + d
here is the error
Error:
Traceback (most recent call last):   File "math.py", line 10, in <module>     b2 = b*b TypeError: can't multiply sequence by non-int of type 'str'
Reply


Messages In This Thread
Cant multiply sequence by non-int type 'str' - by foxtreat - Apr-24-2017, 02:04 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why can't I explicitly call __bool__() on sequence type? quazirfan 11 4,660 Aug-20-2021, 06:49 AM
Last Post: Gribouillis
  Error : "can't multiply sequence by non-int of type 'float' " Ala 3 3,098 Apr-13-2021, 10:33 AM
Last Post: deanhystad
  TypeError: can't multiply sequence by non-int of type 'float' DimosG 3 3,376 Apr-04-2020, 05:16 AM
Last Post: michael1789
  TypeError: can't multiply sequence by non-int of type 'str' emmapaw24 2 2,504 Feb-03-2020, 05:50 PM
Last Post: michael1789
  Type hinting - return type based on parameter micseydel 2 2,500 Jan-14-2020, 01:20 AM
Last Post: micseydel
  TypeError: can't multiply sequence by non-int of type 'str' rregorr 2 2,459 Jun-28-2019, 04:43 PM
Last Post: Yoriz
  TypeError: can't multiply sequence by non-int of type 'str' pythonnoob1234 4 4,302 May-21-2018, 06:12 PM
Last Post: wavic

Forum Jump:

User Panel Messages

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