Underrated step for logic building in programming.

Image
Logic building is a crucial and complex skill in programming. In essence, it is ability to come-up with solution of coding problem and write precise instructions ( or code) that a computer can execute autonomously. This skill requires aligning your thought process with computer and its capabilities. And running through code some-what abstractly to know and predict the behavior of code before it is executed. To be able to do this, one essential step that many beginner programmers overlook is performing dry runs. Understanding Dry Runs The concept of a dry run in programming is straightforward: can you mentally execute your code and predict its output without actually running it on a computer? While this seems simple, it is a challenging task. Typically, we are taught to write code, run it, and observe the output. This cycle is essential because code needs to run to be validated. However, if you rely solely on running your code to understand its behavior, you may struggle with building

Python code # 15 'classes'

 class Student:

    def __init__(self, Roll: int, name: str, faculty: str):
self.__Roll = Roll
self.__name = name
self.__faculty = faculty

def display(self):
print(f"Student({self.__Roll}, '{self.__name}', '{self.__faculty}')")

def set_Roll(self,Roll):
self.__Roll=Roll

def set_name(self,name):
self.__name= name
def set_faculty(self,faculty):
self.__faculty = faculty
def get_Roll(self):
return self.__Roll
def get_name(self):
return self.__name
def get_faculty(self):
return self.__faculty



c = Student(2, 'nn', 'lk')
c.display() # Output: Student(2, 'nn', 'lk')

print(c.get_name())

c.set_Roll( 42)
c.display() # Output: Student(42, 'John', 'lk')
---------------------------------------------------------------------------------------------

class Student:
def __init__(self, Roll: int, name: str, faculty: str):
self.__Roll = Roll
self.__name = name
self.__faculty = faculty

def display(self):
print(f"Student({self.__Roll}, '{self.__name}', '{self.__faculty}')")

def Setter(self, attribute, new_attribute_val):
match attribute:
case 'name':
self.__name = new_attribute_val
case 'Roll':
self.__Roll = new_attribute_val
case 'faculty':
self.__faculty = new_attribute_val

def Getter (self,attribute):
match attribute:
case 'name':
return self.__name
case 'Roll':
return self.__Roll
case 'faculty':
return self.__faculty



c = Student(2, 'nn', 'lk')
c.display() # Output: Student(2, 'nn', 'lk')

print(c.Getter('name'))

c.Setter('Roll', 42)
c.display() # Output: Student(42, 'John', 'lk')

Comments

Popular posts from this blog

Building JavaScript Array Methods from Scratch in 2024 - Easy tutorial for beginners # 1

Build eisenhower matrix with React, firebase and neumorphism ui . (Part one)

Creating a Dynamic Search Bar in React: A Step-by-Step Tutorial