#๐ Need help understanding Errors
115 messages ยท Page 1 of 1 (latest)
@thorn crag
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.
@vague abyss would you like to help me here
sure
Do you understand how classes and class inheritence works?
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))```
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.
this is the first code
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
syntax highlighting??
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
yes i want it
backticks look like this ๐ `
Its usually located below your ESC key
Left of your 1 key
what was the issue exactly?
i want to use this data to my others classes
I don't know ๐๐
!?!!
So back to the Person class. It's very generic. What if you wanna make an Employee class? You don't need to remake another class with the same attributes like name, dob, age, etc. The employee class can have a role associated to it.
okay
first things first
use a dataclass decor
i guess you aren't dealing with abcs
so yeah
use a dataclass decor
yeah
and instead of having parms passed into init of your class
It seems more like OP has a class problem with OP's Quizzes
get them straight as attributes
raelly
please can you fixed it
Sure but the nature of the assignment is creating a quiz
!rule 8 says we can't fix it
8. Do not help with ongoing exams. When helping with homework, help people learn how to do the assignment without doing it for them.
You have to
i need full traceback
i would fix it, given that you'd share the traceback.
this carries no information about where the error is
Of course
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
give it M
First step to fixing is to remove the class inheritence
but how
Can you do that?
if i do it my whole code will crash i think
prove me wrong then
give the whole error log?
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
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>```
So why is self.qus_numbers a NoFormet class?
i just told you the correction above
and secondly,if you're asking something here,be active enough

I am sorry
.
but he didn't pass a string. He inherited a class NoFormet into the UserAns class and somehow that got into the self.qus_numbers
how 2 is a str
i am fixing the entire code
would highlight where you guys are going wrong
exactly. 2 is not a str. Its definitely int
Please ๐ฅบ
so why TypeError: unsupported operand type(s) for +: 'NoFormet' and 'int is
Because class inheritance is still there
Get rid of the class inheritance
Remove the class inheritance from all classes
Delete all class inheritance from all classes
Today my head will be completely destroy
then
Did you do it? If its done, test it again
You'll find a different error
definitely
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>```
Good. Now if you noticed, NoFormet class has no __init__ function
It needs one to pass the n in
yes
So make one please
yes
Its a lot to change and fix but its now usable.
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```
OK good that you made an __init__ function but now you have to change it so that it literally means passing a quiz into the NoFormet class
- Change all
qus_numberin your__init__function to `quiz - In other functions that says
self.qus_numbers, change it toself.quiz.qus_numbers
Can you do that?
I think
@thorn crag https://pastes.dev/ziahbAHwmP
Dont spoonfeed pls
If OP doesn't understand classes, surely won't understand dataclasses
Thank You
OP would need to understand data classes for further editing the code
let him struggle beyond this
!close
This
๐
_
@thorn crag don't use that for your school assignment or something, you'd get duped by the teacher

no way i make it for myself and my friends
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.