#๐Ÿ”’ list problem

275 messages ยท Page 1 of 1 (latest)

arctic sinewBOT
#

@empty sail

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.

empty sail
#

homework assignment for python module in engineering course

leaden kiln
#

so, have you learnt about list.pop?

empty sail
#

i googled it just now

#

i understand that it will remove the last element

#

the code to check last element in list tho

leaden kiln
#

yes, for that you would go about doing negative indexing

graceful owl
#

items[-1] refers to the last element in items

empty sail
#

if list(last variable) == 0:

#

ah ok

#

so if list[-1] == 0:

#

list.pop(-1)

leaden kiln
#

essentially:

        [1,  2,   3,   4,   5]
index:   0   1    2    3    4
rev_index:-5  -4  -3   -2   -1
empty sail
#

ahh yea

#

coming back to me

leaden kiln
#

so now

empty sail
#

so basically -1 is always the "last" because its counted from the right so its always the first

#

ok

leaden kiln
#

you can use your knowledge of looping and think of the conditions you need to check

empty sail
#

while list[-1]==0:

#

list.pop(-1)

#

would that work coz ik while is shit

leaden kiln
#

there is one more condition, you are forgetting that the list should not be trimmed beyond the last element

empty sail
#

oh yea

#

uhh

#

while list[-1] == 0 and len(list)>1:

leaden kiln
#

perfect :)

#

you've done it!

empty sail
#

;-; thanks

solid mirage
#

litearlly 2 lines of code

#

should get 100 on this

empty sail
#

nah that snot the whole assignment

#

๐Ÿ’€

solid mirage
#

best of luck

leaden kiln
#

oof, good luck

empty sail
#

ill send it if ur curious

solid mirage
#

let it be a mystery

empty sail
#

nvm u cant upload files

#

gg

#

part a from Q1 when it goes to like abcdefghi lmao

#

its not too bad

solid mirage
#

ooh you're building to spec

empty sail
#

but im shit at python

solid mirage
#

just use a language you're comfortable then

empty sail
#

idk any other language

#

they kinda just expect us to learn python alongside engineering which is valid but i always struggled with coding one day ill b good tho

leaden kiln
#

its alright, they should've have included python in lectures

solid mirage
empty sail
#

if someone wants to hop on vc for a sec i got a question about how to implement this into the code i got

#

coz we get a unit tests file that is specific

#

about waht it wants

leaden kiln
#

its alr, you can post it here, this is ur thread

solid mirage
#

im not familiar with python's unit tests

#

but with docs available it won't be too bad

empty sail
#

while list[-1] == 0 and len(list)>1:

TypeError: 'type' object is not subscriptable

#

gimme a sec tho might just be like

leaden kiln
#

where is your list defined?

empty sail
#

not calling the correct variable

#

in the unit tests file there is

leaden kiln
#

yes, you need to replace list in the above for ur variables

solid mirage
#

!paste

arctic sinewBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

empty sail
#

my codfe

#

first pic was unit tests

#

ok nvm i did it i think

leaden kiln
#

noop

#

you need to replace list with self.List

#

imagine, list is a type of object

empty sail
leaden kiln
#

yep

empty sail
#

yea

leaden kiln
#

but

#

you need to do self.List.pop

empty sail
#

ah okay

leaden kiln
#

because List is part of yourself

empty sail
#

can u explain self

#

the definition for it

#

sucks

#

i just know to use it

leaden kiln
#

it is essentially, uh

#

well, think of self as an "instance" of an object

empty sail
#

ah yea

leaden kiln
#

class is the blueprint

#

the object that you 3d print is an instance of that blueprint

empty sail
#

right okay

#

yea making sense

#

well im stuck on the next part if ur not doing anything lol

#

its the coefficients and degrees

empty sail
#

last 3 bullet points there

leaden kiln
#

a moment, lemme see

empty sail
#

and the unit tests i sent are the inputs

leaden kiln
#

essentially, the List that you are storing is a list of cofficients for an equasion

empty sail
#

Yes

leaden kiln
#

instead of storing it into List

#

store it into self.cofficients

#

(sadly, you will have to rename a lot of stuff)

empty sail
#

hmm okay what do u mean

leaden kiln
#

instead of self.List = List, you'd have to do self.cofficients = List and then replace everything that used List with cofficients

empty sail
#

uhh

#

line 3 on your pic you mean?

leaden kiln
#

yep

#

and everything that says self.List changes to self.cofficient

#

essentially

empty sail
#

i see

leaden kiln
#

you are renaming a property/attribute

empty sail
#

okay let me give it a try

#

so everything >line 3

#

not the class itself

leaden kiln
#

yep

empty sail
#

well yea thats self, List... ๐Ÿคฆโ€โ™‚๏ธ

#

anyway

#

okay so what about my line of code down there, useless basically

leaden kiln
#

yep, pretty much, you can safely discard it

empty sail
#

ignore the # there for now ig is not relevant too

#

nice okay so how do i assign degrees

leaden kiln
#

uh well

#

how is degrees defined?

#

i mean

#

do you go asscending

#

or descending?

#

because the order of cofficients should match the order of degrees

#

right?

#

how is the equation defined?

empty sail
#

umm

#

hold on a sec

#

uhh

#

can u hop into vc ill screenshare?

#

u dont need a mic

#

its just kinda easier for me to explain and show u what i can see

leaden kiln
#

its alr, just send screenshots

#

!paste
or use this

arctic sinewBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

empty sail
#

i can add u as a friend

leaden kiln
#

sorry, its a personal policy, i don't take dm or fr

empty sail
#

oh yea no worriers

leaden kiln
#

right

#

as you can see

#

the degrees of the polynomial is stored ascendingly

#

so your degrees of polynomials are essentially [0, 1, 2, 3, ..., n]

empty sail
#

right i see

#

so based on the length of the list

leaden kiln
#

yep

#

you create an empty list and add numbers to it in ascending order until its filled with correct length

empty sail
#

soo becuase its like

#

1x^1 + 2x^2 + 3x^3 etc

#

or whatever coefficients

leaden kiln
#

yep

#

but

#

remember

empty sail
leaden kiln
#

that polynomials start with 1x^0 instead of 1x^1

empty sail
#

ah yea

leaden kiln
#

the constant term is x^0

#

noop

#

not that way

#

you need to create an empty list

#

and then add items to it :)

#

using append

empty sail
#

self.degree = ()

#

ah

#

okay

leaden kiln
#

lists are made using [] square brackets instead

empty sail
#

so like self.degree = [] and then

#

self.degree.append(self.coefficients)

#

-1 ?

#

or idk

leaden kiln
#

no no

#

you need to loop, i'll write some examples for you to better understand it, 1 moment

empty sail
#

alright thanks

leaden kiln
#

when you define a list

my_list = []

you can append items to it one by one

my_list.append(5)
my_list.append(3)
print(my_list)

[5, 3]

so you can use the range function, which essentially is a counter

range(4) = [0, 1, 2, 3]

remember, range will never include the last item but will always start from 0

so when you combine this

my_list = []

for item in range(5):
    my_list.append(item)
print(my_list)

[0, 1, 2, 3, 4]

now, use the above knowledge and substitute 5 with whatever number of cofficients you have to make the degrees

empty sail
#

uhh

#

the number of coefficients is variable

leaden kiln
#

yep, that is len() of your self.cofficients

empty sail
#

ah ok

leaden kiln
#

len function returns the length of ur list

empty sail
#

so ok

#

self.coefficients is my list

leaden kiln
#

but

#

you need to create a new list

#

the list where you are appending degrees

empty sail
#

self.degrees = []

leaden kiln
#

so self.degrees = [] is the list you are modifying

#

yep

empty sail
#

yea

#

for i in range(len(self.coefficient)):

leaden kiln
#

yepppp

empty sail
#

self.degrees.append(i)

#

uhh

leaden kiln
#

perfect โœจ

empty sail
#

hot

#

seems to not work

#

am i forgetting that its - 1

#

or something

#

@leaden kiln

#

@leaden kiln pliz help

misty sand
#

@empty sail Okay, so if you give me a minute, I can read through this thread, or you can give me a quick summary on what you currently need help with.

empty sail
#

yeah i can try

#

basically

#

ok so i am making the degree part

#

ill show u code

#

these are the unit tests we get for our code

misty sand
#

This appears to be graded work.

empty sail
#

ok the self.degree.pop[0] is basically a random guess to see if it works i need the degree list to like

#

work

empty sail
misty sand
#

Okay, in which case, the assistance I'm able to provide may be limited, which, given the subject matter, may not be at all noticeable in terms of difference.

empty sail
#

okay

#

well what can u help me with basiccally i need the list of degrees to match the polynomial

misty sand
#

So you're aware, asserts generally should only ever be included in unit testing code, not your code code. There's an option to turn off asserts in Python, which means if you're even relying on them for your program logic, someone could turn those off and someone's day.

empty sail
#

well we have to include assertions in our own code too

#

so im thinking its basically the length of the list of coefficients minus 1

misty sand
#

So long as you understand that may be considered as undesirable beyond this course.

empty sail
#

yes i understand that

misty sand
# empty sail

Is this a comparison testing operation you're wanting to make?

empty sail
#

this is how the coefficients should be defined

#

im just trying how to figure out how to extrapolate self.degrees

#

from self.coefficients

#

as you can see they define it in the tests

misty sand
#

What is a degree?

empty sail
#

its just - 1

misty sand
#

I understand degrees as in 360 degrees, but...

#

Or as in ouch, that is rather hot, isn't it?

empty sail
#

;-;

misty sand
#

Or the third degree.

empty sail
#

Degree of a polynomial ?

misty sand
#

Yes.

empty sail
#

that...

misty sand
#

I'm not mathy.

empty sail
#

ok anyway

#

so bascially i can see this

#

so from this u can kinda decipher that the degree is the polynomial with the front 0's removed minus 1

misty sand
#

I'm just looking at that for loop in your polynomial class.

#

It doesn't appear to be especially useful.

empty sail
#

its also not relevant to what im asking i understand your concern but

#

it is useful

#

the inputs are not limited to what i have shown, you can get non float/intergr inputs

misty sand
#

In mathematics, the degree of a polynomial is the highest of the degrees of the polynomial's monomials (individual terms) with non-zero coefficients. The degree of a term is the sum of the exponents of the variables that appear in it, and thus is a non-negative integer. For a univariate polynomial, the degree of the polynomial is simply the high...

#

I'm sorry, I don't know how to assist you with this without an education in the subject matter.

empty sail
#

yea its okay man

#

i figured it out

misty sand
#

Good.

empty sail
#

in future say that at first haha the first guy that helped me was a genius ;-;

#

this isnt everyones cup of tea its engineering mathmatics python

misty sand
#

I did say I wasn't mathy.

empty sail
#

not fun

misty sand
#

You also said this was a list problem.

empty sail
#

it is

#

this is the line of code that solved it

#

lmao

misty sand
#

Seriously? That's all?

empty sail
#

no maths involved really just reverse engineered the unit tests

#

yesman

#

u probs overcomplicated it

#

although i dont blame u

#

i have been stressing this the last 3021312321 horus

arctic sinewBOT
#
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.

#

๐Ÿ”’ list problem