python - Stranger error with the .join function -
i've been trying write program finds roots of inputted mathematical function. i've started, show here start, , there unused variables.
here wrote function supposed replace term 'x' in function value input, say, 100. here code:
code = list(input("enter mathematical function: ")) lowbound = int(input("enter lower bound: ")) upbound = int(input("enter upper bound: ")) def plugin(mylist, value): in range(len(mylist)): if mylist[i] == 'x': mylist[i] = value #replaces x inputted value return ''.join(mylist) #supposed turn list of characters string print(plugin(code,upbound))
but when run program, error:
traceback (most recent call last): file "python", line 11, in <module> file "python", line 9, in plugin typeerror: sequence item 0: expected str instance, int found
(i'm using online programming platform, file called 'python')
this doesn't make sense me. mylist should not int, , if right data type (str), should list. can explain what's going on here?
you replacing str type (or character) int type.
try instead:
mylist[i] = str(value)
Comments
Post a Comment