#๐Ÿ”’ Following a tutorial!

50 messages ยท Page 1 of 1 (latest)

dark reefBOT
#

@bronze coral

Python help channel opened

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.

pallid timber
#

!e ```py
print(type( ("Hello world") ))
print(type( ("Hello world", ) ))

dark reefBOT
pallid timber
#

options is 1d list of strings

elder sluice
#

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

bronze coral
#

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

bronze coral
elder sluice
#

the inner (...) of your options have no effect.

pallid timber
#

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"),
]```
elder sluice
#

if you fix your options, that displaying issue will be fixed as well

bronze coral
#

yes thats what im trying to understand

#

whats the difference betwen 2d and 1d lists

elder sluice
#

right now your options look like this:

options = (("A. 116"), ("B. 117"), ...)
``` which is *identical* to this:
```py
options = ("A. 116", "B. 117", ...)
bronze coral
#

ohh

elder sluice
#

you probably meant to group the options instead

bronze coral
#

thank you

#

seems to be working now

#

๐Ÿ™

#

am i suppose to close the forum now ?

waxen dagger
#
t = (1,)

for a one-element tuple you need to put a , at the end because otherwise they would simply be brackets

bronze coral
#

is there a specific function that would make me choose a tuple over a normal string

elder sluice
#

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.

waxen dagger
# bronze coral whats the difference between that and

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

bronze coral
#

what do you mean by evaluation order

waxen dagger
#
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

bronze coral
#

so in tuples i shouldnt be using brackets to organize my properties inside of the tuple

waxen dagger
#
a = ((1),(2),(3))
# is identical to
a = (1, 2, 3)

so you can do it but it has no effect

bronze coral
#

if its identical why did it end up making my options come out character by character ?

#

just wondering

waxen dagger
#

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

bronze coral
#

by default

#

im confused sorry

#

!close

dark reefBOT
#
Python help channel closed

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.