Python - __init__() missing 1 required positional argument:

2024/9/21 3:36:58

I'm kinda new to python and I can't get past this error:

   Traceback (most recent call last):File "***", line 63, in <module>bst = Node()
TypeError: __init__() missing 1 required positional argument: 'val'

Basically, the program is a BST which would allow you to insert, search and look for the minimum item by only going left.

Here's the code (sorry, it's hungarian)

class Node:def __init__(self, val):self.ertek = valself.balgyerek = None self.jobbgyerek = Noneself.gyoker = Nonedef beszur(self, pri):if self.gyoker: return self.gyoker.beszur(pri)else: self.gyoker = Node(pri)return Trueif self.ertek == pri: return Falseelif self.ertek > pri: if self.balgyerek: return self.balgyerek.beszur(pri) else:self.balgyerek = Node(pri) return Trueelse: if self.jobbgyerek:return self.jobbgyerek.beszur(pri)else:self.jobbgyerek = Node(pri)return Truedef keres(self, pri):if self.gyoker: return self.gyoker.keres(pri) else: return False if(self.ertek == pri): return Trueelif self.ertek > pri: if self.balgyerek:return self.balgyerek.keres(pri) else:return False else:if self.jobbgyerek:return self.jobbgyerek.keres(pri)else:return Falsedef minimumertek(self): jelenlegi = selfwhile(jelenlegi.balgyerek is not None):jelenlegi = jelenlegi.balgyerekreturn self.ertek bst = Node()
Answer

The __init__ method is run as soon as an object of a class is instantiated. Your __init__ method has two positional arguments: self which refers to the object instance and is passed automatically, and val which is assigned to self.ertek. However, you didn't pass the value of val. Hence, the error. Try passing the value of val at the class instantiation. e.g bst = Node('ertek value')

https://en.xdnf.cn/q/119247.html

Related Q&A

discord py - Custom command prefix doesnt work (no command run)

i have a problem that i cant solve. Im trying to add a prefix switcher for all guilds, that uses my bot. So Ive done that, but currently no command gets triggered and I cant find a solution since hours…

How to use sep parameter in .format?

I just started learning python and Im experimenting new things. isim = input("Name:") soyad = input("Surname:") yaş = input("Age:") edu = input("Education:") ge…

Python table classification

I have different type of data for example:4.5,3.5,U1 4.5,10.5,U2 4.5,6,U1 3.5,10.5,U2 3.5,10.5,U2 5,7,U1 7,6.5,U1I need output:U1: [[4.5, 3.5], [4.5, 6], [5, 7], [7, 6.5]] U2: [[4.5, 10.5], [3.5, 10.5]…

python json.loads / json.load truncates nested json objects?

given the following code: import json foo = {"root":"cfb-score","children":{"gamecode":{"attribute":"global-id"},"gamestate":{&quo…

How to make an encrypted executable file

I have made a tool/program on Ubuntu written in Python. I want to give this to my friend to test on his PC, but I dont want to share the source code.This program has many folders and many .py files. Is…

Organizing pythonic dictionaries for a JSON schema validation

Scenario: I am trying to create a JSON schema validator in python. In this case, I am building a dictionary which contain the information that will be used for the validation.Code:import json import os…

Scraping a specific website with a search box and javascripts in Python

On the website https://sray.arabesque.com/dashboard there is a search box "input" in html. I want to enter a company name in the search box, choose the first suggestion for that name in the d…

Uppercasing letters after ., ! and ? signs in Python

I have been searching Stack Overflow but cannot find the proper code for correcting e.g."hello! are you tired? no, not at all!"Into:"Hello! Are you tired? No, not at all!"

Why does list() function is not letting me change the list [duplicate]

This question already has answers here:How do I clone a list so that it doesnt change unexpectedly after assignment?(24 answers)Python pass by value with nested lists?(1 answer)Closed 2 years ago.If …

How can I explicitly see what self does in python?

Ive read somewhere that the use of ‘self’ in Python converts myobject.method (arg1, arg2) into MyClass.method(myobject, arg1, arg2). Does anyone know how I can prove this? Is it only possible if I…