import random
q = random.randint(10, 100)
w = random.randint(10, 100)
e = (q, " * ", w)
r = int(input(e))
This outputs (i.e):
(60, ' * ', 24)
I tried following this post but i faced an error.
I want output to atleast look like:
(60 * 24)
What I tried was doing
import random
q = random.randint(10, 100)
w = random.randint(10, 100)
**e = (q " * " w)**
r = int(input(e))
Which gave me the error.
CodePudding user response:
A great way to do this is with f-strings
e = f"{q} * {w}"
You just need to start your string with an f, then include any variables in curly braces {}
CodePudding user response:
Your value e
has mixed types. q
and w
are ints while the string is a string. Python prints the types in the tuple as their types. Those quotation marks are not in the values they see, they are a built-in helper in python's display
You will need to coerce all three into the same type to do something with them, eg
>>> eval(str(q) ' * ' str(w))
1482
That's the low level pointer, but higher level I need to ask, what are you trying to do?