Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 69 additions & 68 deletions Add_two_Linked_List.py → Add_Two_Linked_Lists.py
Original file line number Diff line number Diff line change
@@ -1,68 +1,69 @@
class Node:
def __init__(self, data):
self.data = data
self.next = None


class LinkedList:
def __init__(self):
self.head = None

def insert_at_beginning(self, new_data):
new_node = Node(new_data)
if self.head is None:
self.head = new_node
return
new_node.next = self.head
self.head = new_node

def add_two_no(self, first, second):
prev = None
temp = None
carry = 0
while first is not None or second is not None:
first_data = 0 if first is None else first.data
second_data = 0 if second is None else second.data
Sum = carry + first_data + second_data
carry = 1 if Sum >= 10 else 0
Sum = Sum if Sum < 10 else Sum % 10
temp = Node(Sum)
if self.head is None:
self.head = temp
else:
prev.next = temp
prev = temp
if first is not None:
first = first.next
if second is not None:
second = second.next
if carry > 0:
temp.next = Node(carry)

def __str__(self):
temp = self.head
while temp:
print(temp.data, "->", end=" ")
temp = temp.next
return "None"


if __name__ == "__main__":
first = LinkedList()
second = LinkedList()
first.insert_at_beginning(6)
first.insert_at_beginning(4)
first.insert_at_beginning(9)

second.insert_at_beginning(2)
second.insert_at_beginning(2)

print("First Linked List: ")
print(first)
print("Second Linked List: ")
print(second)

result = LinkedList()
result.add_two_no(first.head, second.head)
print("Final Result: ")
print(result)
class Node:
def __init__(self, data):
self.data = data
self.next = None


class LinkedList:
def __init__(self):
self.head = None

def insert_at_beginning(self, new_data):
new_node = Node(new_data)
if self.head is None:
self.head = new_node
return
new_node.next = self.head
self.head = new_node

def add_two_integer_lists(self, first, second):
prev = None
temp = None
carry = 0
while first is not None or second is not None:
first_data = 0 if first is None else first.data
second_data = 0 if second is None else second.data
Sum = carry + first_data + second_data
carry = 1 if Sum >= 10 else 0
Sum = Sum if Sum < 10 else Sum % 10
temp = Node(Sum)
if self.head is None:
self.head = temp
else:
prev.next = temp
prev = temp
if first is not None:
first = first.next
if second is not None:
second = second.next
if carry > 0:
temp.next = Node(carry)

def __str__(self):
temp = self.head
while temp:
print(temp.data, "->", end=" ")
temp = temp.next
return "None"


if __name__ == "__main__":
first = LinkedList()
second = LinkedList()
first.insert_at_beginning(6)
first.insert_at_beginning(4)
first.insert_at_beginning(9)

second.insert_at_beginning(2)
second.insert_at_beginning(2)

print("First Linked List: ")
print(first)
print("Second Linked List: ")
print(second)

result = LinkedList()
result.add_two_integer_lists(first.head, second.head)

print("Final Result: ")
print(result)
3 changes: 2 additions & 1 deletion add_two_nums.py → Add_Two_Numbers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
__author__ = "Nitkarsh Chourasia"
__version__ = "1.0"

from typing import Union

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

# Checking if the given parameters are numerical or not.
Expand Down
16 changes: 16 additions & 0 deletions Add_Two_Numbers_Game.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
user_input = (input("Type 'start' to run program:")).lower()

if user_input == "start":
is_game_running = True
else:
is_game_running = False


while is_game_running:
num1 = int(input("Enter number 1:"))
num2 = int(input("Enter number 2:"))
num3 = num1 + num2
print(f"The sum of {num1} and {num2} is {num3}")
user_input = (input("If you want to end the game, type 'stop':")).lower()
if user_input == "stop":
is_game_running = False
File renamed without changes.
23 changes: 0 additions & 23 deletions Battery_notifier.py

This file was deleted.

File renamed without changes.
File renamed without changes.
17 changes: 17 additions & 0 deletions Find_Greater_Number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def FindGreaterNumber(a, b):
# Python Program to find the largest of two numbers using an arithmetic operator
if a - b > 0:
return a
else:
return b

if __name__ == "__main__":
# Python Program to find the largest of two numbers using an arithmetic operator
a = 37
b = 59

# uncomment following lines to take two numbers from user
# a = float(input("Enter first number: "))
# b = float(input("Enter second number: "))

print(FindGreaterNumber(a, b), " is greater")
24 changes: 24 additions & 0 deletions Find_Greatest_Number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Python program to find the largest number among the three input numbers

def FindGreatestNumber(num1, num2, num3):
if (num1 >= num2) and (num1 >= num3):
largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2
else:
largest = num3
return largest

if __name__ == "__main__":
# change the values of num1, num2 and num3
# for a different result
num1 = 10
num2 = 14
num3 = 12

# uncomment following lines to take three numbers from user
# num1 = float(input("Enter first number: "))
# num2 = float(input("Enter second number: "))
# num3 = float(input("Enter third number: "))

print(FindGreatestNumber(num1, num2, num3))
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def solution(n: int = 600851475143) -> int:
...
TypeError: Parameter n must be int or passive of cast to int.
"""

try:
n = int(n)
except (TypeError, ValueError):
Expand Down Expand Up @@ -63,8 +64,10 @@ def solution(n: int = 600851475143) -> int:


if __name__ == "__main__":
print("Enter a number: ", end="")

# print(solution(int(input().strip())))
import doctest

doctest.testmod()
print(solution(int(input().strip())))
print(solution(int(input().strip())))
66 changes: 66 additions & 0 deletions Psutil_Example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from plyer import notification # pip install plyer
import psutil # pip install psutil
from datetime import datetime

def TestFeature_Memory():
memory = psutil.virtual_memory()
print(f"Total Memory: {memory.total / (1024**3):.2f} GB")
print(f"Available Memory: {memory.available / (1024**3):.2f} GB")
print(f"Used Memory: {memory.used / (1024**3):.2f} GB")
print(f"Memory Usage Percent: {memory.percent}%")

def TestFeature_CPU():
# Get system-wide CPU usage over 1 second
cpu_percent = psutil.cpu_percent(interval=1)
print(f"CPU Usage Percent: {cpu_percent}%")

# Get per-core CPU usage over 1 second
for i, percentage in enumerate(psutil.cpu_percent(interval=1, percpu=True)):
print(f"Core {i}: {percentage}%")

def TestFeature_Battery():
# psutil.sensors_battery() will return the information related to battery
battery = psutil.sensors_battery()
if battery is None:
print("Battery not found")
return

# battery percent will return the current battery prcentage
percent = battery.percent
charging = battery.power_plugged

# Notification(title, description, duration)--to send
# notification to desktop
# help(Notification)
if charging:
if percent == 100:
charging_message = "Unplug your Charger"
else:
charging_message = "Charging"
else:
charging_message = "Not Charging"
message = str(percent) + "% Charged\n" + charging_message

notification.notify("Battery Information", message, timeout=10)

def TestFeature_Network():
net_io = psutil.net_io_counters()
print(f"Bytes Sent: {net_io.bytes_sent}")
print(f"Bytes Received: {net_io.bytes_recv}")

def TestFeature_BootTime():
boot_time_timestamp = psutil.boot_time()
print(f"System booted at: {datetime.fromtimestamp(boot_time_timestamp).strftime('%Y-%m-%d %H:%M:%S')}")

def TestFeature_Processes():
for proc in psutil.process_iter(['pid', 'name']):
print(f"PID: {proc.info['pid']}, Name: {proc.info['name']}")


if __name__ == "__main__":
TestFeature_CPU()
TestFeature_Memory()
TestFeature_Battery()
TestFeature_Network()
TestFeature_BootTime()
TestFeature_Processes()
2 changes: 2 additions & 0 deletions Rotate_Linked_List.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ def Display(self):
L_list.Insert_At_Beginning(6)
L_list.Insert_At_Beginning(11)
L_list.Insert_At_Beginning(9)

print("Linked List Before Rotation: ")
L_list.Display()

print("Linked List After Rotation: ")
L_list.Rotation(4)
L_list.Display()
4 changes: 2 additions & 2 deletions rotatelist.py → Rotate_Number_List.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
N = int(input("Enter The Size Of Array"))
list = []
for i in range(0, N):
temp = int(input("Enter The Intger Numbers"))
temp = int(input("Enter An Integer Number: "))
list.append(temp)


Expand All @@ -10,7 +10,7 @@
# Let's say we want to print list after its d number of rotations.

finalList = []
d = int(input("Enter The Number Of Times You Want To Rotate The Array"))
d = int(input("Enter The Number Of Times You Want To Rotate The Array: "))

for i in range(0, N):
finalList.append(list[(i + d) % N])
Expand Down
16 changes: 0 additions & 16 deletions add_two_number.py

This file was deleted.

2 changes: 1 addition & 1 deletion area_of_square_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def ask_side(self):
n = input("Enter the side of the square: ")
self.side = float(n)
elif isinstance(condition, (int, float)):
for i in range(_=condition):
for i in range(condition):
n = input("Enter the side of the square: ")
self.side = float(n)
# n = input("Enter the side of the square: ")
Expand Down
Loading