#๐ Following a tutorial!
50 messages ยท Page 1 of 1 (latest)
@bronze coral
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
!e ```py
print(type( ("Hello world") ))
print(type( ("Hello world", ) ))
:white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | <class 'str'>
002 | <class 'tuple'>
options is 1d list of strings
I think you did something wrong with the options variable. some other nesting perhaps. right now there isn't really a way for you to distinguishe which set of options belongs to which question
i will be adding a question counter in the nested loop that wont be a problem
the only thing is the answers not formatting correctly
so i should make those tuples aswell ?
it might work if the number of options is always 4. but if that changes, there is no way for you to tell which option belongs to which question, with your current structure
the inner (...) of your options have no effect.
What you are declaring currently is 1d list of strings, those brackets around yours option strings are ignored and you are getting List<str> instead of List<Tuple<str>> (2d list)
For 2d list it should be in format:
opts = [
("A", "B", "C"),
("A", "B", "C"),
]```
if you fix your options, that displaying issue will be fixed as well
it is a 1d tuple not a list
right now your options look like this:
options = (("A. 116"), ("B. 117"), ...)
``` which is *identical* to this:
```py
options = ("A. 116", "B. 117", ...)
ohh
you probably meant to group the options instead
thank you
seems to be working now
๐
am i suppose to close the forum now ?
t = (1,)
for a one-element tuple you need to put a , at the end because otherwise they would simply be brackets
whats the difference between that and
is there a specific function that would make me choose a tuple over a normal string
normal (...) are just a grouping, e.g. like doing (10 + 20) * 30 to change the precedence of things.
In the case of (20) + (30) it doesn't really have any effect, and means the same as 20 + 30
the comma, is what makes it a tuple.
with brackets you control the order of the evaluation and a tuple is a data type, if the tuple has only one element you have to put a comma at the end so that the interpreter knows that you want to create a tuple and do not want to change the evaluation order by means of brackets. the brackets are overloaded, they are not only used for tuples
what do you mean by evaluation order
1 + 1 + 1 is evaluated from left to right so:
1 + 1 + 1 = 2 + 1 = 3
if you use brackets:
1 + (1 + 1) you have 1 + the bracket so the interpreter have to evaluate the bracket first:
1 + (1 + 1) = 1 + 2 = 3
so the mathematical bracket rules
so in tuples i shouldnt be using brackets to organize my properties inside of the tuple
a = ((1),(2),(3))
# is identical to
a = (1, 2, 3)
so you can do it but it has no effect
if its identical why did it end up making my options come out character by character ?
just wondering
because you did:
for option in options[question_num]
options[question_num]
is a string
and
for i in a_string
iterates through every character (unicode codepoint in python)
because you had a 1d tuple
not 2d
are strings 2d ?
by default
im confused sorry
!close
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.