#๐Ÿ”’ code

78 messages ยท Page 1 of 1 (latest)

kind axleBOT
#

@plain wadi

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.

#

Hey @plain wadi!

Please edit your message to use a code block

```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
plain wadi
#
def read2Dictionary():
    dict={}
    file=open("student.txt","r")
    data= file.readlines()
    file.close()
    for line in data:
        line=line.split(",")
        ID=int(line[0])
        Name=line[1]
        grades=float(line[2:])
        dict[ID]=+dict[ID]
        dict.values=list[Name,grades]
    return dict
latent dune
#

You can't assign to a dict's values like that

#

you should also never use dict as a variable name

#

Did you have any questions you wanted to ask about this code?

plain wadi
#

i wanna know whats wrong

#

bc i asked chatgpt and his method isnt one i kow

#

know

#

so i wanna know whats wrong

latent dune
plain wadi
#

no

#

i made it.

#

dict[ID]=+dict[ID] is this part correct?

velvet ridge
latent dune
#

You're nearly there, but just a few things need to change

terse helm
#

don't use dict as the variable name for dict

buoyant pike
#

why are you using += there?

plain wadi
#

what da flip

latent dune
plain wadi
#

pls i just wanna know whats wrong man

#

why we judging

velvet ridge
#

christ the whole party is here

terse helm
plain wadi
latent dune
#

no one is judging

velvet ridge
latent dune
#

I'm trying to get a sense of what you understand so I can better explain

plain wadi
#

is this correct dict[ID]=+dict[ID]

latent dune
#

What do you think this is doing?

plain wadi
#

adding the IDs

#

wait is it

latent dune
plain wadi
#

dict.keys()=dict[ID]

latent dune
#

you eventually need to end up with a format like this

latent dune
#

the format is ID is the key, and then the value is a list

plain wadi
#

well how do i do it

latent dune
#

let's start with that. We need to create a list that will hold the name and the grades

plain wadi
#

so i add a list=[]

latent dune
#

do you know how to create a list and add things to it?

plain wadi
#

under dict={}

latent dune
#

don't use list as a variable name

plain wadi
#

why

latent dune
#

I strongly recommend renaming dict as well

plain wadi
#

my uni does it all the time man

velvet ridge
#

they are builtins

latent dune
#

because list and dict are python datatypes. They already have a meaning

velvet ridge
#

u dont want to override builtins

plain wadi
#

this is just a test

#

okay lst=[]

latent dune
#

name your variables based on what they contain

#

not what they are

#

what is it a list of?

#

what is it a dict of?

plain wadi
#

ok i changed them to

#

dic={}

latent dune
#

students = {} would be a much better name here

plain wadi
#

and lst=[]

latent dune
#

student_info = []

plain wadi
#

um

latent dune
#

use good names

#

break bad habits early

plain wadi
#

i know i do that on exams

#

but practice doesnt need it

latent dune
#

why doesn't it?

#

practice is still code

plain wadi
#

nvm man

latent dune
#

don't be lazy and do it right, even in practice

#

ok so we have a list named student_info

#

what needs to go into that list?

#

@plain wadi still there?

plain wadi
#

yea i dont need help thank u

latent dune
kind axleBOT
#
Python help channel closed for inactivity

This help channel has been closed. 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.