0
What is wrong with this?
I'm trying to make a "future prediction ball" but i don't know where the problem is. This is a try before making it random. ty q = "Atento a las unidades." w = "DeberĂas haber estudiado mĂĄs." e = "Mereces suspender." r = "Me da a mĂ que no has estudiado suficiente." list["q","w","e","r"] print (str(list(0)))
3 Answers
+ 3
Access to any kind of list items must enclose index in square brackets:
print(str(list[0]))
+ 2
Well, first things first:
list = [q, w, e, r]
If you want it to contain the strings "q", "w", "e" and "r" (and not the strings the variables represent, then go ahead. I can't really tell what you want). Anyway, you can't name a variable "list", so that's another thing to look out for.
print(list[0])
The index should be surrounded by square brackets, and not normal, round, semicircular ones. And "str" converts the argument to string, not to use the string the variable name represents. You may be confused by PHP variable variables.
+ 2
# However, I think you want to print the string, not the single letter used to store the string, so you need rather do what @blackcat1111 suggest or:
list = [
"Atento a las unidades.",
"DeberĂas haber estudiado mĂĄs.",
"Mereces suspender.",
"Me da a mĂ que no has estudiado suficiente."
]
print (str(list[0]))
# or use dict:
dict = [
"q" : "Atento a las unidades.",
"w" : "DeberĂas haber estudiado mĂĄs.",
"e" : "Mereces suspender.",
"r" : "Me da a mĂ que no has estudiado suficiente."
]
list = ["q","w","e","r"]
print(dict[list[0]])