#๐Ÿ”’ Need help as a new learner understanding a premade code for a class.

39 messages ยท Page 1 of 1 (latest)

simple sandalBOT
#

@quick sphinx

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.

willow dust
#

Damn it's deleted already

#

That was fast

quick sphinx
#

Didnt know cant send python file :(

willow dust
#

!code

simple sandalBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

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

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

willow dust
#

Code block or this server's pastebin

quick sphinx
#

is it supposed to be in a zip?

willow dust
#

Wdym zip?

quick sphinx
#

I used the pastebin and it zipped?

#

P1 - Calculate Student Average/High Score

Programming Exercise 1.10

[name]

class Student:
def init(self, n, nScores):
self.name = n
self.scores = []
self.nScores = nScores

for idx in range(nScores):
   self.scores.append(0)

def setScore(self, idx, grade):
self.scores[idx] = grade

#[create a function named getNumberOfScores that returns the current number of scores]
def getNumberOfScores():
numscore
return numScores
#[create a function named getName that returns the name of the student]
def getname():
return name
#[create a function named getHighScore that loops through all scores, determines highest and returns it]
def getHighScore():
return
#[create a function named getAverage that sums all the scores, divides them by the number of scores, and returns the result]
def getAverage();

def main(numScores = 3):
from random import randint
"""Tests sorting."""
# Create the list and put 5 students into it
students = list()
names = ("Juan", "Bill", "Stacy", "Maria", "Charley")
for name in names:
s = Student(name, numScores)
for index in range(numScores):
s.setScore(index, randint(70, 100))
students.append(s)

# Print the contents
for s in students:
    print ("Name: ", "%-32s" % s.getName())
    for score in range(numScores):
        print ("Score ", score+1, ":", s.scores[score])
    print ("High Score: ", s.getHighScore())
    print ("Average: %0.3f\n" % s.getAverage())

if name == "main":
main()

#

aha

willow dust
#

You just send the link

quick sphinx
#

ohhh

#

ok my main issue is my class premade code and im really new to python and never have done premade code like this before and on the # is what they want me to do so I think im supposed to make a def with the returns however i dont know what to add to the defs and I dont know if the return is correct seeing how for ref scores are in the first def known as [], then in the last def main as s;setscore? so im just very confused as well as my teacher wanted me to use specific terms and output which ill send after this

#

The first one as the output so I imagine I make multiple inputs and outputs like name, grade 1, grade 2, grade 3, and it gives back the first like then id keep doing it?

#

and the pre-requisites on the right hand side of this as well

willow dust
#

Good lord my eyes

quick sphinx
#

im so sorry

willow dust
#

Dw

#

Just a casual flash bang at 3am

#

I want to help you without giving out straight answers

#

But that's not easy while I'm half asleep

storm hare
#

Do you understand what the code is supposed to do? Without writing any new code that is, do you get that it's generating some students and their scores and then they want you to find the highest score as well as their average score?

quick sphinx
#

I appreciate any help rn, again first day and I don't know anything and she gave us 1 book with nothing really helpful

#

I know the top of the code is to be used in later parts of it i think? such as n, [], and nscores but I dont know where they go in at all (sorry)

willow dust
#

As far as I can see the main function is done

#

But do you understand it?

#

I wouldn't be surprised if you don't understand the stuff happening in the print statements

storm hare
#

We can start in the main() function and just go line by line,

students = list() do you understand what this line does?

willow dust
#

I think he left

#

Gn chat

#

Gl on your journey Melodic

simple sandalBOT
#
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.