Skip to content

Commit 128cd51

Browse files
committed
Renamed several files for clarity
1 parent c1b949b commit 128cd51

8 files changed

+88
-86
lines changed
Lines changed: 69 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,69 @@
1-
class Node:
2-
def __init__(self, data):
3-
self.data = data
4-
self.next = None
5-
6-
7-
class LinkedList:
8-
def __init__(self):
9-
self.head = None
10-
11-
def insert_at_beginning(self, new_data):
12-
new_node = Node(new_data)
13-
if self.head is None:
14-
self.head = new_node
15-
return
16-
new_node.next = self.head
17-
self.head = new_node
18-
19-
def add_two_no(self, first, second):
20-
prev = None
21-
temp = None
22-
carry = 0
23-
while first is not None or second is not None:
24-
first_data = 0 if first is None else first.data
25-
second_data = 0 if second is None else second.data
26-
Sum = carry + first_data + second_data
27-
carry = 1 if Sum >= 10 else 0
28-
Sum = Sum if Sum < 10 else Sum % 10
29-
temp = Node(Sum)
30-
if self.head is None:
31-
self.head = temp
32-
else:
33-
prev.next = temp
34-
prev = temp
35-
if first is not None:
36-
first = first.next
37-
if second is not None:
38-
second = second.next
39-
if carry > 0:
40-
temp.next = Node(carry)
41-
42-
def __str__(self):
43-
temp = self.head
44-
while temp:
45-
print(temp.data, "->", end=" ")
46-
temp = temp.next
47-
return "None"
48-
49-
50-
if __name__ == "__main__":
51-
first = LinkedList()
52-
second = LinkedList()
53-
first.insert_at_beginning(6)
54-
first.insert_at_beginning(4)
55-
first.insert_at_beginning(9)
56-
57-
second.insert_at_beginning(2)
58-
second.insert_at_beginning(2)
59-
60-
print("First Linked List: ")
61-
print(first)
62-
print("Second Linked List: ")
63-
print(second)
64-
65-
result = LinkedList()
66-
result.add_two_no(first.head, second.head)
67-
print("Final Result: ")
68-
print(result)
1+
class Node:
2+
def __init__(self, data):
3+
self.data = data
4+
self.next = None
5+
6+
7+
class LinkedList:
8+
def __init__(self):
9+
self.head = None
10+
11+
def insert_at_beginning(self, new_data):
12+
new_node = Node(new_data)
13+
if self.head is None:
14+
self.head = new_node
15+
return
16+
new_node.next = self.head
17+
self.head = new_node
18+
19+
def add_two_integer_lists(self, first, second):
20+
prev = None
21+
temp = None
22+
carry = 0
23+
while first is not None or second is not None:
24+
first_data = 0 if first is None else first.data
25+
second_data = 0 if second is None else second.data
26+
Sum = carry + first_data + second_data
27+
carry = 1 if Sum >= 10 else 0
28+
Sum = Sum if Sum < 10 else Sum % 10
29+
temp = Node(Sum)
30+
if self.head is None:
31+
self.head = temp
32+
else:
33+
prev.next = temp
34+
prev = temp
35+
if first is not None:
36+
first = first.next
37+
if second is not None:
38+
second = second.next
39+
if carry > 0:
40+
temp.next = Node(carry)
41+
42+
def __str__(self):
43+
temp = self.head
44+
while temp:
45+
print(temp.data, "->", end=" ")
46+
temp = temp.next
47+
return "None"
48+
49+
50+
if __name__ == "__main__":
51+
first = LinkedList()
52+
second = LinkedList()
53+
first.insert_at_beginning(6)
54+
first.insert_at_beginning(4)
55+
first.insert_at_beginning(9)
56+
57+
second.insert_at_beginning(2)
58+
second.insert_at_beginning(2)
59+
60+
print("First Linked List: ")
61+
print(first)
62+
print("Second Linked List: ")
63+
print(second)
64+
65+
result = LinkedList()
66+
result.add_two_integer_lists(first.head, second.head)
67+
68+
print("Final Result: ")
69+
print(result)

add_two_nums.py renamed to Add_Two_Numbers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
__author__ = "Nitkarsh Chourasia"
22
__version__ = "1.0"
33

4+
from typing import Union
45

5-
def addition(num1: typing.Union[int, float], num2: typing.Union[int, float]) -> str:
6+
def addition(num1: Union[int, float], num2: Union[int, float]) -> str:
67
"""A function to add two given numbers."""
78

89
# Checking if the given parameters are numerical or not.

Add_Two_Numbers_Game.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
user_input = (input("Type 'start' to run program:")).lower()
2+
3+
if user_input == "start":
4+
is_game_running = True
5+
else:
6+
is_game_running = False
7+
8+
9+
while is_game_running:
10+
num1 = int(input("Enter number 1:"))
11+
num2 = int(input("Enter number 2:"))
12+
num3 = num1 + num2
13+
print(f"The sum of {num1} and {num2} is {num3}")
14+
user_input = (input("If you want to end the game, type 'stop':")).lower()
15+
if user_input == "stop":
16+
is_game_running = False
File renamed without changes.

add_two_number.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

area_of_square_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def ask_side(self):
6565
n = input("Enter the side of the square: ")
6666
self.side = float(n)
6767
elif isinstance(condition, (int, float)):
68-
for i in range(_=condition):
68+
for i in range(condition):
6969
n = input("Enter the side of the square: ")
7070
self.side = float(n)
7171
# n = input("Enter the side of the square: ")

0 commit comments

Comments
 (0)