#πŸ”’ simple python help beginner

95 messages Β· Page 1 of 1 (latest)

grave tree
#

please help with this question im a complete beginner and so confused, but pls be patient as im brand new

wraith brambleBOT
#

@grave tree

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.

grave tree
#

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

maiden birch
#

hey

grave tree
#

hi

#

no clue where i went wrong

#

probably overcomplicating it too

maiden birch
#

Ok so

#

Do you know what lists are?

mortal vessel
#

Well if you look at the char column, some of the options are 1 character long some are 2

grave tree
#

yeah i sort of know what a list is

mortal vessel
#

That would be the major issue but also you should really be using a list or dictionary as well

maiden birch
#

Do you think you can make a list of the days?

grave tree
#

like list = ["josh","james","john"]

maiden birch
grave tree
#

i can try, what would i store it as though

maiden birch
#

1 list called day

#

1 called shortday

#

1 call char

#

hope u know what to put in the lists

grave tree
#

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

maiden birch
#

πŸ‘€

grave tree
#

what should i do with the lists now

maiden birch
#

can u show what u wrote

grave tree
vague yacht
#

function called DayFormat
gotta love when a course asks you to violate PEP8 😩

maiden birch
#

ong

maiden birch
#

now define your function

grave tree
#

my nea is in a year

#

scary

grave tree
maiden birch
#

Do you understand how indexing an array works?

grave tree
#

sort of

#

i know the index thing would be something like [0:5] at the end

#

but dont really get how to use it

maiden birch
#

!e

my_list = ["a", "b", "c"]

print(my_list[1])  # Will print second element of my_list
wraith brambleBOT
grave tree
#

ah okay

maiden birch
#

Let's just focus on when the type is day for a second

vague yacht
maiden birch
#

when the type is day, you want to return an element from the day list, right?

grave tree
#

yeah

maiden birch
#

Ok so

#

Let's say the given day num is 2

#

That corresponds to tuesday

#

How would you get tuesday from your day list

grave tree
#

print(day[1])

maiden birch
#

yessir

#

how about wednesday?

grave tree
#

print(day[2])

maiden birch
#

yes exactly

#

now notice how the index you're using is always 1 less than the day num

grave tree
#

yeah

maiden birch
#

so given a day num, how would you get the corresponding day from the list?

grave tree
#

wait wdym'

#

wouldnt i js do day[2]

#

or whatever

maiden birch
# grave tree print(day[2])

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]

grave tree
#

idk im sorry im so confused

maiden birch
#

Ok sure no problem

#

Let's write it like

day[index]
``` gets some element from the day list, correct?
grave tree
#

yeah

maiden birch
#

Now when we want Tuesday, num = 2 and index = 1, right?

grave tree
#

yeah

maiden birch
#

For wednesday, num = 3, index = 2

#

Do you see a relation between index and num?

grave tree
#

yeah index is always 1 less

maiden birch
#

exactly

#

so we have index = num - 1

#

therefore to get the numth element from the list, we do day[num - 1]

grave tree
#

ohhh

maiden birch
#

Now can you implement that into your current code?

grave tree
#

ill try

#

wait nvm im confused

#

i thought this would wokr bth

#

tbh

#

let me show u

maiden birch
#

what no

maiden birch
grave tree
#

shi mb

#

okay done

#

i put that bit in

wraith brambleBOT
#
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.