#๐Ÿ”’ Need help understanding Errors

115 messages ยท Page 1 of 1 (latest)

wild anvilBOT
#

@thorn crag

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.

thorn crag
#

@vague abyss would you like to help me here

vague abyss
#

Do you understand how classes and class inheritence works?

thorn crag
#
    def __init__(self, qus_numbers, qusCtype = "1", optionType= "a"):
        self.qus_numbers = qus_numbers
        self.qusCtype = qusCtype
        self.optionType = optionType
        self.quiz_data = []

    def createQuiz(self):
        for quesNum in range(1,self.qus_numbers + 1):
            question = input("Enter question ")
            opn1 = input("Enter option 1 ")
            opn2 = input("Enter option 2 ")
            opn3 = input("Enter option 3 ")
            opn4 = input("Enter option 4 ")
            ans = input("Enter answer : ")
        self.quiz_data.append((quesNum, question, opn1, opn2, opn3, opn4, ans))```
wild anvilBOT
#

Hey @thorn crag!

It looks like you pasted Python code without syntax highlighting.

Please use syntax highlighting to improve the legibility of your code and make it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
thorn crag
#

this is the first code

vague abyss
#

As I said, class inheritence is only used when you're trying to take the common attributes out of multiple objects into one and it inherits from the base

thorn crag
vague abyss
#
class Person:
  def __init__(self, name):
    self.name = name

Example this is a person class.

#

And this is code syntax highlighting

#

Wrap it triple backticks and with a py after the first

vague abyss
#

backticks look like this ๐Ÿ‘‰ `

#

Its usually located below your ESC key

#

Left of your 1 key

swift kiln
#

what was the issue exactly?

thorn crag
thorn crag
swift kiln
vague abyss
swift kiln
#

first things first

#

use a dataclass decor

#

i guess you aren't dealing with abcs

#

so yeah

#

use a dataclass decor

thorn crag
swift kiln
#

and instead of having parms passed into init of your class

vague abyss
#

It seems more like OP has a class problem with OP's Quizzes

swift kiln
#

get them straight as attributes

vague abyss
#

That's OP's original error and script

swift kiln
#

ugh

#

that's a type error my friend

thorn crag
vague abyss
#

Sure but the nature of the assignment is creating a quiz

vague abyss
wild anvilBOT
#

8. Do not help with ongoing exams. When helping with homework, help people learn how to do the assignment without doing it for them.

vague abyss
#

You have to

swift kiln
#

i need full traceback

swift kiln
#

this carries no information about where the error is

swift kiln
#

it just tells us what possibly could have gone wrong

#

you're trying to add an integer to a class

#

which is as logical as adding a string to a NoneType

swift kiln
vague abyss
thorn crag
vague abyss
#

Can you do that?

thorn crag
vague abyss
swift kiln
#

ok

#

you both are wrong here

#

here is the error

#

apparently, you're inheriting ".ques_number" which should be of type int but you're giving and passing a string

#

enable a type checker

#

@novel osprey

thorn crag
# swift kiln give the whole error log?
Enter option 1 NIhad
Enter option 2 Nodi
Enter option 3 Nadim
Enter option 4 Nayem
Enter answer : NIhad
Traceback (most recent call last):
  File "c:\Users\Windows 10\Desktop\Quis\test.py", line 143, in <module>
    m.userAns()
  File "c:\Users\Windows 10\Desktop\Quis\test.py", line 123, in userAns
    for quesNum in range(1,self.qus_numbers + 1):
                           ~~~~~~~~~~~~~~~~~^~~
TypeError: unsupported operand type(s) for +: 'NoFormet' and 'int'
PS C:\Users\Windows 10\Desktop\Quis>```
vague abyss
swift kiln
#

and secondly,if you're asking something here,be active enough

thorn crag
vague abyss
swift kiln
#

would highlight where you guys are going wrong

vague abyss
thorn crag
thorn crag
vague abyss
#

Get rid of the class inheritance

vague abyss
vague abyss
thorn crag
#

Today my head will be completely destroy

vague abyss
#

You'll find a different error

thorn crag
#

now

thorn crag
vague abyss
#

Can you share?

thorn crag
# vague abyss And?
  File "c:\Users\Windows 10\Desktop\Quis\omit.py", line 141, in <module>
    g = NoFormet(n)
        ^^^^^^^^^^^
TypeError: NoFormet() takes no arguments
PS C:\Users\Windows 10\Desktop\Quis>```
vague abyss
#

It needs one to pass the n in

thorn crag
#

yes

vague abyss
#

So make one please

thorn crag
#

yes

vague abyss
#

Its a lot to change and fix but its now usable.

thorn crag
#

    def __init__(self,qus_number):
        self.qus_number = qus_number

    def intiger_list(self):
        n = self.qus_numbers
    
        integer_list = [i for i in range(1,n + 2)]
        return integer_list```
vague abyss
vague abyss
#

Can you do that?

thorn crag
swift kiln
vague abyss
#

If OP doesn't understand classes, surely won't understand dataclasses

swift kiln
#

let him struggle beyond this

swift kiln
vague abyss
#

๐Ÿ™„

swift kiln
#

_

#

@thorn crag don't use that for your school assignment or something, you'd get duped by the teacher

thorn crag
wild anvilBOT
#
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.