#π simple python help beginner
95 messages Β· Page 1 of 1 (latest)
@grave tree
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.
i can copy and paste the code ive got so far, but how do i put it in a box
@maiden birch can bro clutch up again
def DayFormat(num, type):
if num == 1:
print("Monday")
elif num == 2:
print("Tuesday")
elif num == 3:
print("Wednesday")
elif num == 4:
print("Thursday")
elif num == 5:
print("Friday")
elif num == 6:
print("Saturday")
elif num == 7:
print("Sunday")
if type == "day":
print(DayFormat[0:10])
if type == "shortday":
print(DayFormat[0:3])
if type == "char":
print(DayFormat[0:1])
print(DayFormat(1, "day"))
thats my code so far idk whats up with it
hey
Well if you look at the char column, some of the options are 1 character long some are 2
yeah i sort of know what a list is
That would be the major issue but also you should really be using a list or dictionary as well
Do you think you can make a list of the days?
like list = ["josh","james","john"]
very nice yes
i can try, what would i store it as though
So you're going to want to make 3 lists
1 list called day
1 called shortday
1 call char
hope u know what to put in the lists
okay, yeah ill have a go now
i did @maiden birch
i did it on a fresh file tho
so its just got this now
π
what should i do with the lists now
can u show what u wrote
function called DayFormat
gotta love when a course asks you to violate PEP8 π©
ong
praying i can get good enough to understand this in a years timeππππ
my nea is in a year
scary
okay
Do you understand how indexing an array works?
sort of
i know the index thing would be something like [0:5] at the end
but dont really get how to use it
that's slicing, yes
!e
my_list = ["a", "b", "c"]
print(my_list[1]) # Will print second element of my_list
:white_check_mark: Your 3.12 eval job has completed with return code 0.
b
ah okay
Let's just focus on when the type is day for a second
when the type is day, you want to return an element from the day list, right?
yeah
Ok so
Let's say the given day num is 2
That corresponds to tuesday
How would you get tuesday from your day list
print(day[1])
print(day[2])
yes exactly
now notice how the index you're using is always 1 less than the day num
yeah
so given a day num, how would you get the corresponding day from the list?
I give you a variable called num (Let's say num = 2, which means we want tuesday).
Rewrite this in terms of num instead of just doing [1]
idk im sorry im so confused
Ok sure no problem
Let's write it like
day[index]
``` gets some element from the day list, correct?
yeah
Now when we want Tuesday, num = 2 and index = 1, right?
yeah
yeah index is always 1 less
exactly
so we have index = num - 1
therefore to get the numth element from the list, we do day[num - 1]
ohhh
Now can you implement that into your current code?
what no
just put this in your code dawg π
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.