From aed53261b665f7755a37d3fff5289599fc7e52ce Mon Sep 17 00:00:00 2001 From: Hojun Yoon Date: Tue, 1 Oct 2019 00:03:17 +0900 Subject: [PATCH 01/45] Add ANSI color chart script --- .idea/Beginners-Python-Examples.iml | 12 ++++++ .../inspectionProfiles/profiles_settings.xml | 6 +++ .idea/misc.xml | 4 ++ .idea/modules.xml | 8 ++++ .idea/vcs.xml | 6 +++ ansi-colors.py | 42 +++++++++++++++++++ 6 files changed, 78 insertions(+) create mode 100644 .idea/Beginners-Python-Examples.iml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 ansi-colors.py diff --git a/.idea/Beginners-Python-Examples.iml b/.idea/Beginners-Python-Examples.iml new file mode 100644 index 0000000..7c9d48f --- /dev/null +++ b/.idea/Beginners-Python-Examples.iml @@ -0,0 +1,12 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..a2e120d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..9dd9f1a --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ansi-colors.py b/ansi-colors.py new file mode 100644 index 0000000..c270650 --- /dev/null +++ b/ansi-colors.py @@ -0,0 +1,42 @@ +""" +ansi-colors.py +Print 256 ANSI(8bit) color chart +Reference : https://en.wikipedia.org/wiki/ANSI_escape_code + +*** Warning! +In some terminal/OS environments, +this code may display different colors or color may not be displayed properly +""" + +START_ESCAPE_8BIT = "\033[38;5;" +END_ESCAPE = "\033[0;0m" +SQUARE_CHAR = '\u25A0' + + +def print_square_8bit(color): + print(START_ESCAPE_8BIT + str(color) + 'm' + SQUARE_CHAR + END_ESCAPE, end="") + + +print("System standard colors: ", end="") +for i in range(8): + print_square_8bit(i) +print() + +print("System high intensity colors: ", end="") +for i in range(7, 16): + print_square_8bit(i) +print() + +step = 0 +print("216 Colors: ") +for i in range(16, 232): + print_square_8bit(i) + step += 1 + if step % 24 == 0: # Make newline every 24 colors + print() +print() + +print("Grayscale colors: ", end="") +for i in range(232, 256): + print_square_8bit(i) +print() \ No newline at end of file From b6e2e90f819c0b30cf8dc227eefc9925f13963dd Mon Sep 17 00:00:00 2001 From: Hojun Yoon <48780831+hojun-y@users.noreply.github.com> Date: Tue, 1 Oct 2019 00:12:10 +0900 Subject: [PATCH 02/45] Fix typo --- ansi-colors.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ansi-colors.py b/ansi-colors.py index c270650..2d4f174 100644 --- a/ansi-colors.py +++ b/ansi-colors.py @@ -23,7 +23,7 @@ def print_square_8bit(color): print() print("System high intensity colors: ", end="") -for i in range(7, 16): +for i in range(8, 16): print_square_8bit(i) print() @@ -39,4 +39,4 @@ def print_square_8bit(color): print("Grayscale colors: ", end="") for i in range(232, 256): print_square_8bit(i) -print() \ No newline at end of file +print() From 879bd6b965ead1308808719cb63e528830231db7 Mon Sep 17 00:00:00 2001 From: Hojun Yoon Date: Tue, 1 Oct 2019 00:13:29 +0900 Subject: [PATCH 03/45] delete IDE files --- .idea/Beginners-Python-Examples.iml | 12 ------------ .idea/inspectionProfiles/profiles_settings.xml | 6 ------ .idea/misc.xml | 4 ---- .idea/modules.xml | 8 -------- .idea/vcs.xml | 6 ------ 5 files changed, 36 deletions(-) delete mode 100644 .idea/Beginners-Python-Examples.iml delete mode 100644 .idea/inspectionProfiles/profiles_settings.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/Beginners-Python-Examples.iml b/.idea/Beginners-Python-Examples.iml deleted file mode 100644 index 7c9d48f..0000000 --- a/.idea/Beginners-Python-Examples.iml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 105ce2d..0000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index a2e120d..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 9dd9f1a..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From 96a71d3826cafa458d4bf26d5c8e366aea51e142 Mon Sep 17 00:00:00 2001 From: Geethmaka Dissanayake Date: Tue, 1 Oct 2019 01:27:54 +0530 Subject: [PATCH 04/45] Added simple turtle example --- Drawing_With_Turtle.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Drawing_With_Turtle.py diff --git a/Drawing_With_Turtle.py b/Drawing_With_Turtle.py new file mode 100644 index 0000000..ecd2987 --- /dev/null +++ b/Drawing_With_Turtle.py @@ -0,0 +1,11 @@ +#This is a example for turtle +#This shows how to draw a star +#For more tutorials visit https://www.tutorialspoint.com/turtle-programming-in-python + +# import turtle library +import turtle +my_pen = turtle.Turtle() +for i in range(50): + my_pen.forward(50) + my_pen.right(144) +turtle.done() \ No newline at end of file From c682b85bcbe7da318061857acacdca677829ebe2 Mon Sep 17 00:00:00 2001 From: Geethmaka Dissanayake Date: Tue, 1 Oct 2019 01:50:25 +0530 Subject: [PATCH 05/45] Abstract Drawing From Turtle --- Turtle_Drawing.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Turtle_Drawing.py diff --git a/Turtle_Drawing.py b/Turtle_Drawing.py new file mode 100644 index 0000000..f979857 --- /dev/null +++ b/Turtle_Drawing.py @@ -0,0 +1,21 @@ +import turtle + +ninja = turtle.Turtle() + +ninja.speed(10) + +for i in range(180): + ninja.forward(100) + ninja.right(30) + ninja.forward(20) + ninja.left(60) + ninja.forward(50) + ninja.right(30) + + ninja.penup() + ninja.setposition(0, 0) + ninja.pendown() + + ninja.right(2) + +turtle.done() \ No newline at end of file From ad281cac612de48ab52502e059ebc2113e7e5ea2 Mon Sep 17 00:00:00 2001 From: Joytaylor Date: Mon, 7 Oct 2019 10:56:19 -0500 Subject: [PATCH 06/45] Update find_square_root.py less loop time and includes 0 and 1 --- find_square_root.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/find_square_root.py b/find_square_root.py index 15d0920..4c6212f 100644 --- a/find_square_root.py +++ b/find_square_root.py @@ -7,7 +7,7 @@ def find_square_root(x): if type(x) == str: return "Expected an integer! Cannot find square root of an string!" - for i in range(x): + for i in range(0, (x/2 )+2): if i ** 2 == x: return i return "{} is not a perfect square".format(x) From 1d3b00a2bd106cf9b42d04da483a8c0373df17b1 Mon Sep 17 00:00:00 2001 From: MIP2000 <49375670+MIP2000@users.noreply.github.com> Date: Tue, 8 Oct 2019 03:50:13 +0300 Subject: [PATCH 07/45] Create Display ASCII Value of a Character.md --- Display ASCII Value of a Character.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Display ASCII Value of a Character.md diff --git a/Display ASCII Value of a Character.md b/Display ASCII Value of a Character.md new file mode 100644 index 0000000..04ad522 --- /dev/null +++ b/Display ASCII Value of a Character.md @@ -0,0 +1,7 @@ +# ASCII Value of Character + +# Simply ender a character from the keyboard +user_input = input('Give me a character: ') + +# Print the ASCII value of assigned character +print("The ASCII value of '" + user_input + "' is", ord(user_input)) From 0187627d4e29719486eb6383a235b75d128e4d38 Mon Sep 17 00:00:00 2001 From: MIP2000 <49375670+MIP2000@users.noreply.github.com> Date: Tue, 8 Oct 2019 03:50:45 +0300 Subject: [PATCH 08/45] Rename Display ASCII Value of a Character.md to Display ASCII Value of a Character.py --- ...lue of a Character.md => Display ASCII Value of a Character.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Display ASCII Value of a Character.md => Display ASCII Value of a Character.py (100%) diff --git a/Display ASCII Value of a Character.md b/Display ASCII Value of a Character.py similarity index 100% rename from Display ASCII Value of a Character.md rename to Display ASCII Value of a Character.py From 40ccb5583473913dfe93f1be48234082ffe88270 Mon Sep 17 00:00:00 2001 From: Somnath chatterjee Date: Fri, 11 Oct 2019 16:22:22 +0530 Subject: [PATCH 09/45] Adding bubble sort algorithm --- bubble sort.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 bubble sort.py diff --git a/bubble sort.py b/bubble sort.py new file mode 100644 index 0000000..a28bad4 --- /dev/null +++ b/bubble sort.py @@ -0,0 +1,47 @@ +'''Bubble Sort +Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order. +Example: +First Pass: +( 5 1 4 2 8 ) –> ( 1 5 4 2 8 ), Here, algorithm compares the first two elements, and swaps since 5 > 1. +( 1 5 4 2 8 ) –> ( 1 4 5 2 8 ), Swap since 5 > 4 +( 1 4 5 2 8 ) –> ( 1 4 2 5 8 ), Swap since 5 > 2 +( 1 4 2 5 8 ) –> ( 1 4 2 5 8 ), Now, since these elements are already in order (8 > 5), algorithm does not swap them. + +Second Pass: +( 1 4 2 5 8 ) –> ( 1 4 2 5 8 ) +( 1 4 2 5 8 ) –> ( 1 2 4 5 8 ), Swap since 4 > 2 +( 1 2 4 5 8 ) –> ( 1 2 4 5 8 ) +( 1 2 4 5 8 ) –> ( 1 2 4 5 8 ) +Now, the array is already sorted, but our algorithm does not know if it is completed. The algorithm needs one whole pass without any swap to know it is sorted. + +Third Pass: +( 1 2 4 5 8 ) –> ( 1 2 4 5 8 ) +( 1 2 4 5 8 ) –> ( 1 2 4 5 8 ) +( 1 2 4 5 8 ) –> ( 1 2 4 5 8 ) +( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )''' + +# Python program for implementation of Bubble Sort + +def bubbleSort(arr): + n = len(arr) + + # Traverse through all array elements + for i in range(n): + + # Last i elements are already in place + for j in range(0, n-i-1): + + # traverse the array from 0 to n-i-1 + # Swap if the element found is greater + # than the next element + if arr[j] > arr[j+1] : + arr[j], arr[j+1] = arr[j+1], arr[j] + +# Driver code to test above +arr = [64, 34, 25, 12, 22, 11, 90] + +bubbleSort(arr) + +print ("Sorted array is:") +for i in range(len(arr)): + print ("%d" %arr[i]), From aee5135fcc76f33b9601596b6337bcc3990799da Mon Sep 17 00:00:00 2001 From: Somnath chatterjee Date: Fri, 11 Oct 2019 16:32:22 +0530 Subject: [PATCH 10/45] Program to find factorial of a number --- factorial.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 factorial.py diff --git a/factorial.py b/factorial.py new file mode 100644 index 0000000..a58fc51 --- /dev/null +++ b/factorial.py @@ -0,0 +1,7 @@ +def factorial(n): + if n == 0: + return 1 + else: + return n * factorial(n-1) +n=int(input("Input a number to compute the factiorial : ")) +print(factorial(n)) From ddd9b2b445647df898170a37ea4259ce22dc04e6 Mon Sep 17 00:00:00 2001 From: akshara Date: Sat, 25 Jul 2020 22:53:18 +0530 Subject: [PATCH 11/45] Added an input statement --- days_you_lived.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/days_you_lived.py b/days_you_lived.py index c41e4a1..4b1118e 100644 --- a/days_you_lived.py +++ b/days_you_lived.py @@ -1,7 +1,6 @@ # We assume that given dates are correct # and # solved for problem set in cs course on udacity.com - from calendar import isleap def daysBetweenDates(year1, month1, day1, year2, month2, day2): @@ -26,3 +25,12 @@ def daysBetweenDates(year1, month1, day1, year2, month2, day2): days += sum(dom) return days + +date1=input("Enter a first date in YYYY-MM-DD format") +year1,month1,day1=map(int,date1.split('-')) + +date2=input("Enter a second date in YYYY-MM-DD format") +year2,month2,day2=map(int,date2.split('-')) + +days=daysBetweenDates(year1, month1, day1, year2, month2, day2) +print("Number of days between {} and {} is \n {}".format(date1,date2,abs(days))) From 18be0061775be1207fea0eb8f2f94e22005e001e Mon Sep 17 00:00:00 2001 From: Tzara Date: Sun, 20 Sep 2020 18:20:09 -0500 Subject: [PATCH 12/45] added a simple conways game of life --- conways.py | 140 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 conways.py diff --git a/conways.py b/conways.py new file mode 100644 index 0000000..a834d76 --- /dev/null +++ b/conways.py @@ -0,0 +1,140 @@ +''' +-conway's game of life +-made by Tzara Northcut @Mecknavorz +-requires pygame +''' + +#import the stuff we need +import pygame, sys, time + +#----------------------------------------- +#initalize some variables and other things +#----------------------------------------- +width = 6 #cell size width +height = 6 #cell size height +space = 2 #thickness of world lines +#create the 2d array where we actually store vairables of cells +world = [[0 for x in range(100)] for y in range(100)] + +#initialzie pygame +pygame.init() + +size = [100*(width+space)+space, 100*(height+space)+space] #window size +screen = pygame.display.set_mode(size) #make the window the right size + +#set spme colors +BLACK = ( 0, 0, 0) #background color +WHITE = (255, 255, 255) #color of world +GREEN = ( 0, 0, 0) #color of cells that are alive and well +RED = (255, 0, 0) #colors of the cells about to die + +#speed stuff +clock = pygame.time.Clock() #clock used to manage game speed +pause = True #used to control the steps, might not need this +laststep = time.time() + +#used to keep runing until the game is closed +done = False + +#------------------------------------- +#some functions to be used in the game +#------------------------------------- +#determine #of cells nearby +def getclose(x, y): + nearby = 0 + #avoid out of bounds error and make the grid a torroid + if(x+1) > 99: + x = 0 + if(y+1) > 99: + y = 0 + #swcan nearby squares and if there's something there add 1 to the count + if world[x-1][y-1]: + nearby += 1 + if world[x][y-1]: + nearby += 1 + if world[x+1][y-1]: + nearby += 1 + if world[x-1][y]: + nearby += 1 + if world[x+1][y]: + nearby += 1 + if world[x-1][y+1]: + nearby += 1 + if world[x][y+1]: + nearby += 1 + if world[x+1][y+1]: + nearby += 1 + return nearby + +#calculate next step +def nextStep(): + for x in range(len(world)): + for y in range(len(world[0])): + near = getclose(x, y) + if near < 2: #if there are less than two neighbors then kill the cell + world[x][y] = 0 + if near > 3: #if there are more than three neighbors then kill the cell + world[x][y] = 0 + if (world[x][y] == 0) and (near == 3): #if there are 3 neighbors near a dead cell, revive it + world[x][y] = 1 + +#clear the board +def clear(): + for x in range(len(world)): + for y in range(len(world[0])): + world[x][y] = 0 + +#--------------------- +#the initale game loop +#--------------------- +while not done: + #to make sure the game quits when we need it to + for event in pygame.event.get(): + if event.type == pygame.QUIT: + done = True + elif event.type == pygame.MOUSEBUTTONDOWN: #if we get a click + pos = pygame.mouse.get_pos() #find where the click was + #change the pixel coords into game coords + x = pos[1] // (height+space) + y = pos[0] // (width+space) + #add or remove the cell that's there + if world[x][y] == 0: #if the tile is empty add a cell + world[x][y] = 1 + #print("nearby: ", getclose(x, y)) #used for debugging + else: #else if there's something there, remove the cell + world[x][y] = 0 + #print("click: ", pos, "grid coord: ", x, y) #debug stuff + elif event.type == pygame.KEYDOWN: #pause the game when space is pressed + if event.key == pygame.K_SPACE: + #print('space pressed') + if pause: + pause = False + elif not pause: + pause = True + elif event.key == pygame.K_RIGHT: #if we presws the right key go forward a step + nextStep() #calculate the next + elif event.key == pygame.K_ESCAPE: + clear() + + + #draw the world + screen.fill(BLACK) + #maybe move this to a seprate function to help with effeciency? + for x in range(len(world)): + for y in range(len(world[0])): + color = WHITE + if world[x][y] == 1: + color = GREEN + pygame.draw.rect(screen, color, [(space+width)*y+space, (space+height)*x+space, width, height]) + + #set frame rate + clock.tick(60) + if (not pause) and ((time.time() - laststep) > .1): + laststep = time.time() + #print(laststep) + nextStep() + #update screen + pygame.display.flip() + +#if we;ve gotten this far (eg out of the while loop) we know it's time to quit +pygame.quit() From d06573c76650f7e49b74bf80f9b2e91399021dd5 Mon Sep 17 00:00:00 2001 From: Pragati Kalra <43950367+Pragati-Kalra@users.noreply.github.com> Date: Fri, 25 Sep 2020 13:39:09 +0530 Subject: [PATCH 13/45] Updated_bubblesort.py --- algorithms/sorting/bubble_sort.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/algorithms/sorting/bubble_sort.py b/algorithms/sorting/bubble_sort.py index 9074ad0..e1fe084 100644 --- a/algorithms/sorting/bubble_sort.py +++ b/algorithms/sorting/bubble_sort.py @@ -67,7 +67,7 @@ def sort_(arr, temporary = False, reverse = False): # See proper explaination # at: https://www.geeksforgeeks.org/bubble-sort/ # a good site! - +#can add flag to reduce time complexity # Testing tests = [[7, 8, 9, 6, 4, 5, 3, 2, 1, 15], [1, 90, 1110, 1312, 1110, 98, 76, 54, 32, 10], ] # Add your test cases From b300cfd8056e0d2e28d4600baee62d7702e3e6b1 Mon Sep 17 00:00:00 2001 From: Vamsi Krishna <33099230+V-V-K@users.noreply.github.com> Date: Thu, 1 Oct 2020 03:10:05 +0530 Subject: [PATCH 14/45] Create Pattern Program This is a fun pattern program which I learned! --- Pattern Program | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Pattern Program diff --git a/Pattern Program b/Pattern Program new file mode 100644 index 0000000..cf143f1 --- /dev/null +++ b/Pattern Program @@ -0,0 +1,5 @@ +rows = 6 +for num in range(rows): + for i in range(num): + print(num, end=" ") # print number + print(" ") From 683b24019cae4eebc549ce845776b0bd943a1ea6 Mon Sep 17 00:00:00 2001 From: Vamsi Krishna <33099230+V-V-K@users.noreply.github.com> Date: Thu, 1 Oct 2020 03:14:25 +0530 Subject: [PATCH 15/45] Create Pattern Python Program Reverse pattern 5 5 5 5 5 4 4 4 4 3 3 3 2 2 1 --- Pattern Python Program | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Pattern Python Program diff --git a/Pattern Python Program b/Pattern Python Program new file mode 100644 index 0000000..759efd3 --- /dev/null +++ b/Pattern Python Program @@ -0,0 +1,6 @@ +rows = 5 +for i in range(rows, 0, -1): + num = i + for j in range(0, i): + print(num, end=' ') + print("\r") From fc38aec5c81c89c50fd913359223b80f5d023c4a Mon Sep 17 00:00:00 2001 From: Vamsi Krishna <33099230+V-V-K@users.noreply.github.com> Date: Thu, 1 Oct 2020 03:16:25 +0530 Subject: [PATCH 16/45] Create Medium level python program 1 2 1 3 2 1 4 3 2 1 5 4 3 2 1 --- Medium level python program | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Medium level python program diff --git a/Medium level python program b/Medium level python program new file mode 100644 index 0000000..74a4b84 --- /dev/null +++ b/Medium level python program @@ -0,0 +1,5 @@ +rows = 6 +for row in range(1, rows): + for column in range(row, 0, -1): + print(column, end=' ') + print("") From 4054e21b90865acc6e9dd7275b61266d23670d6a Mon Sep 17 00:00:00 2001 From: Vamsi Krishna <33099230+V-V-K@users.noreply.github.com> Date: Thu, 1 Oct 2020 03:18:02 +0530 Subject: [PATCH 17/45] Create Double the number pattern 1 2 1 4 2 1 8 4 2 1 16 8 4 2 1 32 16 8 4 2 1 64 32 16 8 4 2 1 128 64 32 16 8 4 2 1 --- Double the number pattern | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Double the number pattern diff --git a/Double the number pattern b/Double the number pattern new file mode 100644 index 0000000..6864bfd --- /dev/null +++ b/Double the number pattern @@ -0,0 +1,5 @@ +rows = 9 +for i in range(1, rows): + for j in range(-1+i, -1, -1): + print(format(2**j, "4d"), end=' ') + print("") From 4d302fbfc19288f3bfa86b5d3cdfc3f27f7aa640 Mon Sep 17 00:00:00 2001 From: abhi032 <35945322+abhi032@users.noreply.github.com> Date: Thu, 1 Oct 2020 06:40:28 +0530 Subject: [PATCH 18/45] socket programming added 2 new programs for file transfer of socket programming --- client_file.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 client_file.py diff --git a/client_file.py b/client_file.py new file mode 100644 index 0000000..1d9a17f --- /dev/null +++ b/client_file.py @@ -0,0 +1,20 @@ +import socket +server_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) +host = socket.gethostbyname(socket.gethostname()) +port = 12345 +x = input("Enter file name : ") +server_socket.connect((host,port)) +name = server_socket.recv(1024).decode() +name = name.split('.')[-1] +name = x+'.'+name + +f = open(name,'wb') +while True : + c_msg = server_socket.recv(1024) + if c_msg == 'EOF'.encode() : + f.close() + server_socket.close() + break + f.write(c_msg) + + From 6b527859f66d83b6325e2087a3e6dc1257e6e7c2 Mon Sep 17 00:00:00 2001 From: abhi032 <35945322+abhi032@users.noreply.github.com> Date: Thu, 1 Oct 2020 06:43:08 +0530 Subject: [PATCH 19/45] Socket programming Added both server and client file to transfer data on local maching , it supports every file Hope U may like it :) --- server_file.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 server_file.py diff --git a/server_file.py b/server_file.py new file mode 100644 index 0000000..9389c5f --- /dev/null +++ b/server_file.py @@ -0,0 +1,22 @@ +import socket +server_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) +host = socket.gethostbyname(socket.gethostname()) +port = 12345 +server_socket.bind((host,port)) +print("Server socket sucessfully Created on IP : {} at port {} ".format(host,port)) +server_socket.listen() +print("Server is waiting for clients to connect .... \n\n") +client_socket,client_addr = server_socket.accept() +print("Client is connected") +print("Client's IP {}:{}\n\n".format(*client_addr)) +f = open(input("Enter path to your file "),'rb') +name =f.name +client_socket.send(name.encode()) +for line in f: + client_socket.send(line) +else : + client_socket.send("EOF".encode()) + client_socket.close() + server_socket.close() + + From c57cfda271b777b5975a2b0240701fc4f6abcb06 Mon Sep 17 00:00:00 2001 From: Hiruthic <56349092+hiruthic2002@users.noreply.github.com> Date: Thu, 1 Oct 2020 14:35:36 +0530 Subject: [PATCH 20/45] Updated dictionary.py [Python2] to Python3 Haven't changed the formatting, only rewritten in Python3 syntaxes --- dictionary.py | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/dictionary.py b/dictionary.py index ea2c9b2..31f2c21 100644 --- a/dictionary.py +++ b/dictionary.py @@ -1,4 +1,3 @@ - global dictionary dictionary = {} @@ -9,53 +8,53 @@ def __init__(self, word, meaning): def add_new(self): dictionary[self.word] = self.meaning - print "Word Successfully Added" + print("Word Successfully Added") def delete_word(self): try: del dictionary[self.word] - print "Word Successfully Deleted" + print("Word Successfully Deleted") except KeyError: - print "The Word Does Not Exist in Dictionary. Try Again!" + print("The Word Does Not Exist in Dictionary. Try Again!") def edit_word(self): try: dictionary[self.word] = self.meaning - print "Word Was Successfully Edited" + print("Word Was Successfully Edited") except KeyError: - print "The Word You Trying To Edit Does Not Exist in Dictionary!" + print("The Word You Trying To Edit Does Not Exist in Dictionary!") def view_word(self): try: - print dictionary[self.word] + print(dictionary[self.word]) except KeyError: - print "The Word is not in Dictionary." + print("The Word is not in Dictionary.") def view_all(self): for i in dictionary.keys(): print(i + " : " + dictionary[i]) def start(): - get_op = raw_input("Add, Delete, Edit, View, View all : ") + get_op = input("Add, Delete, Edit, View, View all : ") if get_op in ["add", "Add"]: - get_word = raw_input("Word to add : ") - get_meaning = raw_input("Meaning : ") + get_word = input("Word to add : ") + get_meaning = input("Meaning : ") new = Dict(get_word, get_meaning) new.add_new() elif get_op in ["delete", "Delete"]: - get_word_to_del = raw_input("Word to delete : ") + get_word_to_del = input("Word to delete : ") delete = Dict(get_word_to_del, None) delete.delete_word() elif get_op in ["edit", "Edit"]: - get_word_to_edit = raw_input("Word to edit : ") - get_new_meaning = raw_input("New meaning : ") + get_word_to_edit = input("Word to edit : ") + get_new_meaning = input("New meaning : ") mean = Dict(get_word_to_edit, get_new_meaning) mean.edit_word() elif get_op in ["view", "View"]: - get_word_to_view = raw_input("Word to view : ") + get_word_to_view = input("Word to view : ") view = Dict(get_word_to_view, None) view.view_word() @@ -64,15 +63,15 @@ def start(): nothing.view_all() else: - print "Invalid Input. Try again!" + print("Invalid Input. Try again!") def end(): quit() def main(): while True: - s_or_e = raw_input("Start or End : ") - if s_or_e == "Start": + s_or_e = input("Start or End : ") + if s_or_e.lower() == "start": start() print(" ") continue @@ -82,4 +81,4 @@ def main(): if __name__ == "__main__": - main() \ No newline at end of file + main() From 37b8d36907558ff98bd61970519e7a52ad169862 Mon Sep 17 00:00:00 2001 From: Hiruthic <56349092+hiruthic2002@users.noreply.github.com> Date: Thu, 1 Oct 2020 17:23:18 +0530 Subject: [PATCH 21/45] Diffe Hellman algorithm in python One of a key-exchange method in internet privacy. Not the most secure one but still in use in combination with RSA and sha256 and more --- useful_scripts/Diffe_Hellman.py | 74 +++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 useful_scripts/Diffe_Hellman.py diff --git a/useful_scripts/Diffe_Hellman.py b/useful_scripts/Diffe_Hellman.py new file mode 100644 index 0000000..f4d80ea --- /dev/null +++ b/useful_scripts/Diffe_Hellman.py @@ -0,0 +1,74 @@ +import random, hashlib + +def list_prime(): + for num in range(3, 1000): + # all prime numbers are greater than 1 + if num > 1: + for i in range(2, num): + if (num % i) == 0: + break + else: + print(num, end=', ') + +def is_prime(n): + """if num > 1: + for i in range(2, num//2): + if (num % i) == 0: + return False + break + else: + return True + else: + return False""" + # Corner cases + if (n <= 1) : + return False + if (n <= 3) : + return True + + # This is checked so that we can skip + # middle five numbers in below loop + if (n % 2 == 0 or n % 3 == 0) : + return False + + i = 5 + while(i * i <= n) : + if (n % i == 0 or n % (i + 2) == 0) : + return False + i = i + 6 + + return True + +def cost(h, cost): + for i in range(cost): + h = hashlib.sha3_512(h.encode()).hexdigest() + return h + +print("type 'prime' to choose from list") +prime = input("Enter a largest prime number you can think of >>> ") +if prime == 'prime': + list_prime() + prime = int(input("Enter a largest prime number you can think of >>> ")) +else: + prime = int(prime) + +if is_prime(prime): + private = int(input("Enter your private key>>> ")) + public = random.randint(0, 999999999) + my_share = (public**private)%prime + my_exchange_key = cost(hashlib.sha3_512(str(my_share).encode()).hexdigest(), 5) + print() + print(f"Your exchange key is --> {my_exchange_key}") + print('*' * 100) + + bob_private = int(input("Enter Bob's private key>>> ")) + bob_share = (public**private)%prime + bob_exchange_key = cost(hashlib.sha3_512(str(bob_share).encode()).hexdigest(), 5) + print() + print(f"Bob'sexchange key is --> {bob_exchange_key}") + print() + print(f"my_exchange_key == bob_exchange_key\n{my_exchange_key == bob_exchange_key}") + print('*' * 100) + +else: + print("This is not a prime number") From 9b7491a7659ba08fa159a2bd582d7ad1bcac6cdf Mon Sep 17 00:00:00 2001 From: Hiruthic <56349092+hiruthic2002@users.noreply.github.com> Date: Thu, 1 Oct 2020 17:25:27 +0530 Subject: [PATCH 22/45] A python script to plot the ping over time I use it while gaming to know when my ping messed up the game-play and made other players to spam my calling me a noob --- useful_scripts/pinger.py | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 useful_scripts/pinger.py diff --git a/useful_scripts/pinger.py b/useful_scripts/pinger.py new file mode 100644 index 0000000..302dbb1 --- /dev/null +++ b/useful_scripts/pinger.py @@ -0,0 +1,47 @@ +import subprocess +from datetime import datetime +import matplotlib.pyplot as plt + +pings = [] +losses = [] +times = [] +i = 0 + +def update_line(): + plt.plot(times, pings) + plt.xticks(rotation=45) + plt.draw() + + +try: + plt.show() + while True: + output = subprocess.check_output("ping 8.8.8.8", shell=True) + losses.append(output.decode().split()[-18]) + output = output.decode().split()[-1] + time = datetime.now().strftime("%H:%M:%S") + pings.append(int(output.strip("ms"))) + times.append(time) + i += 1 + # update_line() +except KeyboardInterrupt: + pings = [int(i) for i in pings] + losses = [int(i) for i in losses] + + plt.figure() + plt.subplot(211) + plt.xticks(rotation=45) + plt.ylabel("ping (MS) - avg") + plt.plot(times, pings) + + if sum(losses) != 0: + plt.subplot(212) + plt.plot(times, losses) + + + plt.xticks(rotation=45) + plt.ylabel("Loss") + plt.show() + + + From a38341906ae06c9dd152b983a68936650032bf4a Mon Sep 17 00:00:00 2001 From: HenryBass <63601449+HenryBass@users.noreply.github.com> Date: Fri, 2 Oct 2020 18:25:41 -0400 Subject: [PATCH 23/45] Added a freefall calculator --- math/FreefallCalculator | 62 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 math/FreefallCalculator diff --git a/math/FreefallCalculator b/math/FreefallCalculator new file mode 100644 index 0000000..47e8164 --- /dev/null +++ b/math/FreefallCalculator @@ -0,0 +1,62 @@ +# Gravity Simulation + +import math +import numpy as np + +# Welcome + +print("Welcome to a 1D Free Fall Simulation. Please enter only in metric integers. ") +print("You will enter the amount of time you want to simulate, it includes information about impact, \n" + "even if the simulation stops before impact.") + +# Constants + +g = 9.81 + +# Variables + +height = int(input("Drop Height: ")) +timeElapsed = 1 +runTime = int(input("How long do you want to record data from the fall? ")) +location = 0 +mass = int((input("Mass: "))) +timeToImpact = 0 + +# Simulation + +print("Second by second info of free fall in given time.") +while timeElapsed <= runTime and timeToImpact >= 0 and location >= 0: + + # Equations + + distanceTraveled = (g * timeElapsed ** 2) / 2 + velocity = distanceTraveled / timeElapsed + location = height - distanceTraveled + momentum = mass * velocity + timeToImpact = math.sqrt((2 * height) / g) + + # Print Stats + + print("\nTime to simulation end: " + str(runTime - timeElapsed)) + print('Y Location: ' + str(location) + 'M') + print('Velocity: ' + str(velocity) + 'M/S') + print('Distance Traveled: ' + str(distanceTraveled) + 'M') + print('Momentum: ' + str(momentum) + 'N') + print('Time Elapsed: ' + str(timeElapsed)) + print('Rough time to impact: ' + str(timeToImpact - timeElapsed)) + print() + + # Add to time elapsed + + timeElapsed = timeElapsed + 1 + +# Print impact results + +print("\n The Simulation is done. \n") +print("*This is printed even if the object fell past the ground, or never hit it.* \n Info on impact: ") +print('Y Location: 0M') +print('Velocity: ' + str(height / runTime) + 'M/S') +print('Distance Traveled: ' + str(height) + 'M') +print('Momentum: ' + str(mass * (height / runTime)) + 'N') +print('Time Spent in free fall: ' + str(timeToImpact)) +print() From 859a8a64c533982eb3de8762905befc38f8cf021 Mon Sep 17 00:00:00 2001 From: Anonymous InfoBro <132287085+IntelligentInfoBro@users.noreply.github.com> Date: Wed, 15 Nov 2023 18:27:43 -0800 Subject: [PATCH 24/45] Create for_loop_fibonnaci A simple program using for loop to print fibonacci sequence till nth member of the sequence --- simple_scripts/for_loop_fibonnaci | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 simple_scripts/for_loop_fibonnaci diff --git a/simple_scripts/for_loop_fibonnaci b/simple_scripts/for_loop_fibonnaci new file mode 100644 index 0000000..0f17dab --- /dev/null +++ b/simple_scripts/for_loop_fibonnaci @@ -0,0 +1,9 @@ +#printing fibonnaci series till nth element +def print_fibonacci(n): + current_no = 1 + prev_no = 0 + for i in range(n): + print(current_no, end = " ") + prev_no,current_no = current_no, current_no + prev_no + +print_fibonacci(10) From ef824f5400b4b917bb6f555302b6be84e5f765a7 Mon Sep 17 00:00:00 2001 From: Anonymously known <132287085+IntelligentInfoBro@users.noreply.github.com> Date: Fri, 17 Nov 2023 11:09:52 -0800 Subject: [PATCH 25/45] Create Binary_to_decimal A program to convert binary string(s) to decimal. --- math/Binary_to_decimal | 62 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 math/Binary_to_decimal diff --git a/math/Binary_to_decimal b/math/Binary_to_decimal new file mode 100644 index 0000000..5a82316 --- /dev/null +++ b/math/Binary_to_decimal @@ -0,0 +1,62 @@ +# binary_to_decimal.py +# +# Description: A program to evaluate binary to decimal. +# +# Author: Chaitanya Mittal +# Date: 2023-11-17 10:14:20.288913 + +"""Idea: +- def a function to decode 1 byte: + - get the list + - get value by multiplying each element with 2** its index from reverse (pattern observation) + .... (instead of this we can multiply index to list reversed)...... + - return the sum of value + +- get input +- split it to get rid of spaces (assume user is well behaved and will enter 1-space separated string only) +- convert each byte and compile result in a list +- print the converted bytes separated by space +""" + + +def byte_decode(binary): + # Convert binary string to list + lst = list(binary)[::-1] + + # Initialize variables + length = len(binary) + sum = 0 + + # Loop through each character in the binary string + for i in range(length): + # Calculate value of each bit + value = int(lst[i]) * (2 ** i) + + # Add value to the sum + sum += value + + # Return the final sum + return sum + +# ____ Main Program ____ # + +# Get input of the required binary string +binary = input("Binary: ").split(" ") +""" TESTING PURPOSES +string = ("01010101 01101110 01100100 01100101 0110010 00100000 01011001 01101111 01110101 01110010 00100000 01010011 01100101 01100001 01110100").split() +binary = list(string)""" + +# Initialize an empty list to store 'evaluated' bytes +bytes_translated = list() +#translate the byte and append it to the list +for byte in binary: + bytes_translated.append(byte_decode(byte)) + +# Print the output +print(f'Evaluated: ', end = "") +for byte in bytes_translated: + print(byte, end = " ") +print() + + + From 7f28e0da493b9b2031e365e9f3a1adabc78f3454 Mon Sep 17 00:00:00 2001 From: virinchi-addanki <123866097+virinchi-addanki@users.noreply.github.com> Date: Sat, 20 Jan 2024 13:42:47 +0530 Subject: [PATCH 26/45] Add files via upload --- algorithms/string/check_anagram.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 algorithms/string/check_anagram.py diff --git a/algorithms/string/check_anagram.py b/algorithms/string/check_anagram.py new file mode 100644 index 0000000..ec2532a --- /dev/null +++ b/algorithms/string/check_anagram.py @@ -0,0 +1,26 @@ +'''An anagram is a word or phrase created by rearranging the letters of another word or phrase. +For example, the word "heart" can be rearranged to form the word "earth". +So, "heart" and "earth" are anagrams of each other.''' + +def check_anagram(str1,str2): + # Remove all spaces from both the strings + # and convert them to lowercase + str1 = str1.replace(" ","").lower() + str2 =str2.replace(" ","").lower() + # if the length of both strings are not equal then return false + if len(str1) != len(str2): + return False + count1 = {} + count2 = {} + for i in range(len(str1)): + count1[str1[i]] = 1+count1.get(str1[i],0) + count2[str2[i]] = 1+count2.get(str2[i],0) + for c in count1: + if count1[c] != count2.get(c,0): + return False +str1 = input() +str2 = input() +if check_anagram(str1,str2): + print(f"{str1} and {str2} are anagrams") +else: + print(f"{str1} and {str2} are anagrams") \ No newline at end of file From bb89e002684443267de85b1f0ac29066385aefa7 Mon Sep 17 00:00:00 2001 From: "Do (A)I Matter?" <20800689+zeta-punk-x1@users.noreply.github.com> Date: Fri, 2 Aug 2024 20:35:21 +0000 Subject: [PATCH 27/45] Update README.md --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 16e2c9f..5e56f1e 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,19 @@ # Beginners-Python-Programs Basic python CLI programs as examples.
All the examples are useful examples.
-These examples are of beginners' level.
+These examples are of beginner level.

-Hey guys, I wrote these programs when I was just starting up with programming, now I realize that many of 'em feel very un-professional and useless so I decided to go one by one through all and make 'em more useful and professional! +Update: I wrote these programs when I was just starting out with programming, now I realize that many of them seem quite amateur in their rendering so I've decided to audit through all of them and update them according to my current capabilities.
-Note: In 2.x versions input isn't useful. Similarly, in 3.x versions raw_input isn't useful. Also, xrange() and other methods are discontinued or changed in 3.x versions of Python. Change the keywords accordingly! +Note: In 2.x versions input isn't useful. Similarly, in 3.x versions raw_input isn't useful. Also, xrange() and other methods are discontinued or changed in 3.x versions of Python. Change the keywords accordingly.
-NOTE: WORK IN PROGRESS!
-Files Outside Particular Folders/Directories have not been checked yet!
-Files inside, directories offer much elegant code and explaination
+NOTE: Work in progress
+Files outside particular directories have not been checked yet
+Files inside, directories offer better code and explanation
 
 


Also see this : Beginners-Python-Examples/CONTRIBUTING.md
-contact kalpaktake@gmail.com +contact electric.vision.x19@gmail.com From 87d706005ff72b55724a98a85515052847990b5d Mon Sep 17 00:00:00 2001 From: "Do (A)I Matter?" <20800689+zeta-punk-x1@users.noreply.github.com> Date: Fri, 2 Aug 2024 20:37:19 +0000 Subject: [PATCH 28/45] Update README.md --- README.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 5e56f1e..415e98e 100644 --- a/README.md +++ b/README.md @@ -2,18 +2,16 @@ Basic python CLI programs as examples.
All the examples are useful examples.
These examples are of beginner level.
+ +Note: In 2.x versions input isn't useful. Similarly, in 3.x versions raw_input isn't useful. Also, xrange() and other methods are discontinued or changed in 3.x versions of Python. Change the keywords accordingly. +
Update: I wrote these programs when I was just starting out with programming, now I realize that many of them seem quite amateur in their rendering so I've decided to audit through all of them and update them according to my current capabilities.
-Note: In 2.x versions input isn't useful. Similarly, in 3.x versions raw_input isn't useful. Also, xrange() and other methods are discontinued or changed in 3.x versions of Python. Change the keywords accordingly. - -
-NOTE: Work in progress
-Files outside particular directories have not been checked yet
+Files outside particular directories have not been checked yet 
Files inside, directories offer better code and explanation -
-
+

Also see this : Beginners-Python-Examples/CONTRIBUTING.md
contact electric.vision.x19@gmail.com From 5430199480c06187fe0543efe270230d78385adb Mon Sep 17 00:00:00 2001 From: "Do (A)I Matter?" <20800689+zeta-punk-x1@users.noreply.github.com> Date: Fri, 2 Aug 2024 20:37:54 +0000 Subject: [PATCH 29/45] Update README.md --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 415e98e..4f7338e 100644 --- a/README.md +++ b/README.md @@ -8,10 +8,9 @@ Note: In 2.x versions input isn't useful. Similarly, in 3.x versions raw_input i
Update: I wrote these programs when I was just starting out with programming, now I realize that many of them seem quite amateur in their rendering so I've decided to audit through all of them and update them according to my current capabilities.
- +
Files outside particular directories have not been checked yet
Files inside, directories offer better code and explanation - -

+
Also see this : Beginners-Python-Examples/CONTRIBUTING.md
contact electric.vision.x19@gmail.com From 19e68eaeac610aa44648fbc3b92cad400396c36a Mon Sep 17 00:00:00 2001 From: "Do (A)I Matter?" <20800689+zeta-punk-x1@users.noreply.github.com> Date: Fri, 2 Aug 2024 20:38:11 +0000 Subject: [PATCH 30/45] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 4f7338e..1be585e 100644 --- a/README.md +++ b/README.md @@ -12,5 +12,6 @@ Update: I wrote these programs when I was just starting out with programming, no Files outside particular directories have not been checked yet
Files inside, directories offer better code and explanation
+
Also see this : Beginners-Python-Examples/CONTRIBUTING.md
contact electric.vision.x19@gmail.com From a7b718c524b0f20a89b15a3d69479cc7a98b4140 Mon Sep 17 00:00:00 2001 From: Kal <20800689+kal179@users.noreply.github.com> Date: Sun, 12 Jan 2025 19:36:33 +0530 Subject: [PATCH 31/45] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 1be585e..68cd977 100644 --- a/README.md +++ b/README.md @@ -14,4 +14,3 @@ Files inside, directories offer better code and explanation

Also see this : Beginners-Python-Examples/CONTRIBUTING.md
-contact electric.vision.x19@gmail.com From a872c36b8fac64055800ea280fc2b1282ffa6a0c Mon Sep 17 00:00:00 2001 From: Kal <20800689+kal179@users.noreply.github.com> Date: Tue, 22 Apr 2025 22:39:10 +0530 Subject: [PATCH 32/45] Update dictionary.py --- dictionary.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/dictionary.py b/dictionary.py index 4d6a6b3..58dacc4 100644 --- a/dictionary.py +++ b/dictionary.py @@ -9,27 +9,27 @@ def __init__(self, word, meaning): def add_new(self): dictionary[self.word] = self.meaning - print ("Word Successfully Added") + print("Word Successfully Added") def delete_word(self): try: del dictionary[self.word] - print ("Word Successfully Deleted") + print("Word Successfully Deleted") except KeyError: - print "(The Word Does Not Exist in Dictionary. Try Again!") + print("The Word Does Not Exist in Dictionary. Try Again!") def edit_word(self): try: dictionary[self.word] = self.meaning - print ("Word Was Successfully Edited") + print("Word Was Successfully Edited") except KeyError: - print ("The Word You Trying To Edit Does Not Exist in Dictionary!") + print("The Word You Trying To Edit Does Not Exist in Dictionary!") def view_word(self): try: - print (dictionary[self.word]) + print(dictionary[self.word]) except KeyError: - print ("The Word is not in Dictionary.") + print("The Word is not in Dictionary.") def view_all(self): for i in dictionary.keys(): @@ -64,7 +64,7 @@ def start(): nothing.view_all() else: - print ("Invalid Input. Try again!") + print("Invalid Input. Try again!") def end(): quit() From 297ab0f4b04971e61e41adcf7016c1df76ee6560 Mon Sep 17 00:00:00 2001 From: Barrenkala Veera Venkata Karthik <140957865+Karthik110505@users.noreply.github.com> Date: Tue, 22 Apr 2025 22:47:31 +0530 Subject: [PATCH 33/45] Merge pull request #100 from Karthik110505/new_branch Thanks for the addition! --- armstrong_number.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/armstrong_number.py b/armstrong_number.py index dd09992..f0e8d9d 100644 --- a/armstrong_number.py +++ b/armstrong_number.py @@ -6,12 +6,14 @@ # initialize sum sum = 0 +# finding the length of num +n = len(str(num)) # find the sum of the cube of each digit temp = num while temp > 0: digit = temp % 10 - sum += digit ** 3 + sum += digit ** n # power of n temp //= 10 # display the result From bf36be5189164f7ca2ffecf5d2082cbbbd39bf1f Mon Sep 17 00:00:00 2001 From: Alok070899 <47590533+Alok070899@users.noreply.github.com> Date: Thu, 1 Oct 2020 15:15:09 +0530 Subject: [PATCH 34/45] Create bigo_notation.py This Python program can give a graphical idea of Big-O notation. Hope This can also help you. --- algorithms/analysis/bigo_notation.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 algorithms/analysis/bigo_notation.py diff --git a/algorithms/analysis/bigo_notation.py b/algorithms/analysis/bigo_notation.py new file mode 100644 index 0000000..34e673e --- /dev/null +++ b/algorithms/analysis/bigo_notation.py @@ -0,0 +1,24 @@ +from math import log +import numpy as np +import matplotlib.pyplot as plt +%matplotlib inline +plt.style.use('bmh') + +# Set up runtime comparisons + +n = np.linspace(1,10,1000) +labels = ['Constant','Logarithmic','Linear','Log Linear','Quadratic','Cubic','Exponential'] +big_o = [np.ones(n.shape),np.log(n),n,n*np.log(n),n**2,n**3,2**n] + +# Plot setup + +plt.figure(figsize=(12,10)) +plt.ylim(0,50) + +for i in range(len(big_o)): + plt.plot(n,big_o[i],label = labels[i]) + + +plt.legend(loc=0) +plt.ylabel('Relative Runtime') +plt.xlabel('n') From caae97a36b947ebf4dd924b2353f95e66fa768b9 Mon Sep 17 00:00:00 2001 From: Kal <20800689+kal179@users.noreply.github.com> Date: Tue, 22 Apr 2025 23:33:04 +0530 Subject: [PATCH 35/45] Create bigo_notation.py --- bigo_notation.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 bigo_notation.py diff --git a/bigo_notation.py b/bigo_notation.py new file mode 100644 index 0000000..34e673e --- /dev/null +++ b/bigo_notation.py @@ -0,0 +1,24 @@ +from math import log +import numpy as np +import matplotlib.pyplot as plt +%matplotlib inline +plt.style.use('bmh') + +# Set up runtime comparisons + +n = np.linspace(1,10,1000) +labels = ['Constant','Logarithmic','Linear','Log Linear','Quadratic','Cubic','Exponential'] +big_o = [np.ones(n.shape),np.log(n),n,n*np.log(n),n**2,n**3,2**n] + +# Plot setup + +plt.figure(figsize=(12,10)) +plt.ylim(0,50) + +for i in range(len(big_o)): + plt.plot(n,big_o[i],label = labels[i]) + + +plt.legend(loc=0) +plt.ylabel('Relative Runtime') +plt.xlabel('n') From 721a68e3ccf81b49cc9ee84358ace187c6b7f2dd Mon Sep 17 00:00:00 2001 From: Kal <20800689+kal179@users.noreply.github.com> Date: Tue, 22 Apr 2025 23:34:45 +0530 Subject: [PATCH 36/45] Update bigo_notation.py --- bigo_notation.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bigo_notation.py b/bigo_notation.py index 34e673e..76670b7 100644 --- a/bigo_notation.py +++ b/bigo_notation.py @@ -1,3 +1,5 @@ +# Contribution from https://github.com/Alok070899 + from math import log import numpy as np import matplotlib.pyplot as plt From 661a8203ba20b3322df23fd4dc4e0c5594492a7b Mon Sep 17 00:00:00 2001 From: Kal <20800689+kal179@users.noreply.github.com> Date: Tue, 22 Apr 2025 23:37:40 +0530 Subject: [PATCH 37/45] Create map_example.py --- map_example.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 map_example.py diff --git a/map_example.py b/map_example.py new file mode 100644 index 0000000..7a14c01 --- /dev/null +++ b/map_example.py @@ -0,0 +1,13 @@ +# Contribution by https://github.com/tyadav4268 + +#This is to demonstrate the use of map function in python +#Problem Statement: Using the function Map, count the number of words that start with ‘S’ in input_list. +#Sample Input: ['Santa Cruz','Santa fe','Mumbai','Delhi'] +#Sample Output: 2 + +#Solution: +input_list = ['Santa Cruz','Santa fe','Mumbai','Delhi'] + +count = sum(map(lambda x: x[0] == 'S', input_list)) + +print(count) # Output: 2 From a990dbdeb24a3dab0c20ea822c3e3e6960b5b78e Mon Sep 17 00:00:00 2001 From: Kal <20800689+kal179@users.noreply.github.com> Date: Wed, 23 Apr 2025 00:07:38 +0530 Subject: [PATCH 38/45] Create snake_game.py --- snake_game.py | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 snake_game.py diff --git a/snake_game.py b/snake_game.py new file mode 100644 index 0000000..b84b4a8 --- /dev/null +++ b/snake_game.py @@ -0,0 +1,128 @@ +# Contribution by https://github.com/Karan9034 + +import pygame +import sys +import random + +class Snake(object): + def __init__(self): + self.length=1 + self.positions=[((SCREEN_WIDTH/2),(SCREEN_HEIGHT/2))] + self.direction=random.choice([UP,DOWN,LEFT,RIGHT]) + self.color=(17,24,47) + + def get_head_position(self): + return self.positions[0] + + def turn(self,point): + if self.length>1 and (point[0] * -1, point[1] * -1) == self.direction: + return + else: + self.direction=point + + def move(self): + cur=self.get_head_position() + x,y=self.direction + new=((cur[0] + (x*GRIDSIZE))%SCREEN_WIDTH,(cur[1]+(y*GRIDSIZE))%SCREEN_HEIGHT) + if len(self.positions)>2 and new in self.positions[2:]: + pygame.quit() + sys.exit() + else: + self.positions.insert(0,new) + if len(self.positions)>self.length: + self.positions.pop() + + def draw(self,surface): + for p in self.positions: + r=pygame.Rect((p[0],p[1]),(GRIDSIZE,GRIDSIZE)) + pygame.draw.rect(surface,self.color,r) + pygame.draw.rect(surface,(93,216,228),r,1) + + def handle_keys(self): + for event in pygame.event.get(): + if event.type==pygame.QUIT: + pygame.quit() + sys.exit() + elif event.type==pygame.KEYDOWN: + if event.key==pygame.K_UP: + self.turn(UP) + elif event.key==pygame.K_DOWN: + self.turn(DOWN) + elif event.key==pygame.K_LEFT: + self.turn(LEFT) + elif event.key==pygame.K_RIGHT: + self.turn(RIGHT) + elif event.key==pygame.K_ESCAPE: + pygame.quit() + sys.exit() + +class Food(object): + def __init__(self): + self.position=(0,0) + self.color=(233,163,49) + self.randomize_position() + + def randomize_position(self): + self.position=(random.randint(0,GRID_WIDTH-1)*GRIDSIZE,random.randint(0,GRID_HEIGHT-1)*GRIDSIZE) + + def draw(self,surface): + r=pygame.Rect((self.position[0],self.position[1]),(GRIDSIZE,GRIDSIZE)) + pygame.draw.rect(surface,self.color,r) + pygame.draw.rect(surface,(93,216,228),r,1) + +def drawGrid(surface): + for y in range(0,int(GRID_HEIGHT)): + for x in range(0,int(GRID_WIDTH)): + if (x+y)%2==0: + r=pygame.Rect((x*GRIDSIZE,y*GRIDSIZE),(GRIDSIZE,GRIDSIZE)) + pygame.draw.rect(surface,(200,200,200),r) + else: + rr=pygame.Rect((x*GRIDSIZE,y*GRIDSIZE),(GRIDSIZE,GRIDSIZE)) + pygame.draw.rect(surface,(100,100,100),rr) + +SCREEN_WIDTH=480 +SCREEN_HEIGHT=480 + +GRIDSIZE=20 +GRID_WIDTH=SCREEN_WIDTH/GRIDSIZE +GRID_HEIGHT=SCREEN_HEIGHT/GRIDSIZE + +UP=(0,-1) +DOWN=(0,1) +LEFT=(-1,0) +RIGHT=(1,0) + +def main(): + pygame.init() + + clock=pygame.time.Clock() + screen=pygame.display.set_mode((SCREEN_WIDTH,SCREEN_HEIGHT),0,32) + pygame.display.set_caption("Snake") + surface=pygame.Surface(screen.get_size()) + surface=surface.convert() + drawGrid(surface) + + snake=Snake() + food= Food() + + myfont=pygame.font.SysFont("monospace",16) + + score=0 + while True: + clock.tick(10) + snake.handle_keys() + drawGrid(surface) + snake.move() + if snake.get_head_position()==food.position: + snake.length+=1 + score+=1 + food.randomize_position() + snake.draw(surface) + food.draw(surface) + screen.blit(surface,(0,0)) + text=myfont.render("Score: {0}".format(score),1,(0,0,0)) + screen.blit(text,(5,10)) + pygame.display.update() + +if __name__=="__main__": + main() From fbfe0931a11ff1d947697e60bc2a31b3a2aeb322 Mon Sep 17 00:00:00 2001 From: Kal <20800689+kal179@users.noreply.github.com> Date: Wed, 23 Apr 2025 00:10:29 +0530 Subject: [PATCH 39/45] Delete .idea directory --- .idea/.gitignore | 3 -- .idea/Beginners-Python-Examples.iml | 12 ------ .idea/inspectionProfiles/Project_Default.xml | 43 ------------------- .../inspectionProfiles/profiles_settings.xml | 6 --- .idea/misc.xml | 4 -- .idea/modules.xml | 8 ---- .idea/vcs.xml | 6 --- 7 files changed, 82 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/Beginners-Python-Examples.iml delete mode 100644 .idea/inspectionProfiles/Project_Default.xml delete mode 100644 .idea/inspectionProfiles/profiles_settings.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 26d3352..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/.idea/Beginners-Python-Examples.iml b/.idea/Beginners-Python-Examples.iml deleted file mode 100644 index 8b8c395..0000000 --- a/.idea/Beginners-Python-Examples.iml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index cbe978f..0000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 105ce2d..0000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index dc9ea49..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 9dd9f1a..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From c1eb67d4654c69ededd26c363d4e58e65dd4cf1e Mon Sep 17 00:00:00 2001 From: Kal <20800689+kal179@users.noreply.github.com> Date: Wed, 23 Apr 2025 00:56:03 +0530 Subject: [PATCH 40/45] Contribution by https://github.com/nightwarriorftw --- bell_number.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 bell_number.py diff --git a/bell_number.py b/bell_number.py new file mode 100644 index 0000000..4b47e6f --- /dev/null +++ b/bell_number.py @@ -0,0 +1,24 @@ +# Contribution by https://github.com/nightwarriorftw + +#Python program to print bell number +#Bell Number:-Let S(n, k) be total number of partitions of n elements into k sets. The value of n’th Bell Number is sum of S(n, k) for k = 1 to n. Value of S(n, k) can be defined recursively as, S(n+1, k) = k*S(n, k) + S(n, k-1) +A sample Bell triangle is as follows: +1 +1 3 +3 8 13 +13 23 33 43 +#The code to print the bell triangle is as follows- +#--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +n=int(input("enter the number of bell")) #taking value from the user +bell=0 #initialising bell to 'zero' +k=0 #initialising k to 'zero' +for i in range(0,n): #loop for changing rows from 0 to n + for j in range(0,i+1): #printing columns + if j==0 and i>0: #repeating the last number of previous row in new row + print(bell,'',end='') #printing first number of each line + else: + k=(i**2)+1+bell #to generate other numbers of line + print(k,'',end='') #printing other number in lines + bell=k #updating value of bell + print('\n') #for moving into next lines +print("last number of bell is",bell) From 60073f5bf85257b822e6950cfa36c14c6e9f7e09 Mon Sep 17 00:00:00 2001 From: Kal <20800689+kal179@users.noreply.github.com> Date: Wed, 23 Apr 2025 01:00:16 +0530 Subject: [PATCH 41/45] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 68cd977..c9aaa63 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ # Beginners-Python-Programs +I created this repo years ago when in school. From now it will be available as a public archive only.

+ Basic python CLI programs as examples.
All the examples are useful examples.
These examples are of beginner level.
From 491e90501afe1b21a0301d277e8f84ca6dfd188f Mon Sep 17 00:00:00 2001 From: Kal <20800689+kal179@users.noreply.github.com> Date: Wed, 23 Apr 2025 01:00:55 +0530 Subject: [PATCH 42/45] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c9aaa63..84a5388 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Beginners-Python-Programs -I created this repo years ago when in school. From now it will be available as a public archive only.

+Repository will be available as a public archive only.

Basic python CLI programs as examples.
All the examples are useful examples.
From eb419df6d04f16f7dda1b0867d291088d50889c8 Mon Sep 17 00:00:00 2001 From: Kal <20800689+kal179@users.noreply.github.com> Date: Tue, 18 Nov 2025 03:13:01 +0530 Subject: [PATCH 43/45] Final Update to README.md Message that informs visitors that starting 18 Nov 2025 this Repo will be available as a Public Archive only. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 84a5388..18a8244 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Beginners-Python-Programs -Repository will be available as a public archive only.

+[18 Nov 2025] Final Update: This was my first Repo and I created it when I was very young and completely new to computer programming. I no longer have time to update/maintain it in anyway.
Thus, starting today, This Repository will be available as a Public Archive only.

Basic python CLI programs as examples.
All the examples are useful examples.
From 68e3a0ef5860de90ee294fd97ef5d2d55c31ddf5 Mon Sep 17 00:00:00 2001 From: Kal <20800689+kal179@users.noreply.github.com> Date: Tue, 18 Nov 2025 03:24:41 +0530 Subject: [PATCH 44/45] Last Final Update Ever (xD) README.md Message that informs visitors that starting 18 Nov 2025 this Repo will be available as a Public Archive only. P.S. changed like one word from previous commit. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 18a8244..af0ed67 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Beginners-Python-Programs -[18 Nov 2025] Final Update: This was my first Repo and I created it when I was very young and completely new to computer programming. I no longer have time to update/maintain it in anyway.
Thus, starting today, This Repository will be available as a Public Archive only.

+[18 Nov 2025] Final Update: This was my first Repo and I created it when I was quite young and completely new to computer programming. I no longer have time to update/maintain it in anyway.
Thus, starting today, This Repository will be available as a Public Archive only.

Basic python CLI programs as examples.
All the examples are useful examples.
From 37af7e647f3feff86896683fbd53f3d5c5b16fab Mon Sep 17 00:00:00 2001 From: Kal <20800689+kal179@users.noreply.github.com> Date: Tue, 18 Nov 2025 03:26:51 +0530 Subject: [PATCH 45/45] Last Final Commit Ever README.md Final Commit: Message that informs visitors that starting 18 Nov 2025 this Repo will be available as a Public Archive only. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index af0ed67..619621c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Beginners-Python-Programs -[18 Nov 2025] Final Update: This was my first Repo and I created it when I was quite young and completely new to computer programming. I no longer have time to update/maintain it in anyway.
Thus, starting today, This Repository will be available as a Public Archive only.

+[18 Nov 2025] Final Update: This was my first Repo and I created it when I was fairly young and completely new to computer programming. I no longer have time to update/maintain it in anyway.
Thus, starting today, This Repository will be available as a Public Archive only.

Basic python CLI programs as examples.
All the examples are useful examples.