From 1fceec0d13f19f09c596d2624bd54526950295bd Mon Sep 17 00:00:00 2001 From: utkxxrsh <64093818+utkxxrsh@users.noreply.github.com> Date: Mon, 26 Oct 2020 21:39:27 +0530 Subject: [PATCH 01/35] Create Find RunnerUp.md --- Find RunnerUp.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Find RunnerUp.md diff --git a/Find RunnerUp.md b/Find RunnerUp.md new file mode 100644 index 00000000..15d94cb3 --- /dev/null +++ b/Find RunnerUp.md @@ -0,0 +1,7 @@ +if __name__=="__main__": + n = int(input()) + arr = map(int, input().split()) + arr = list(set(list(arr))) + ar = len(arr) + arr = sorted(arr) + print(arr[ar-2]) From f595c1ecee73741f56c4c926231ae4995b517a56 Mon Sep 17 00:00:00 2001 From: lavesh123 <73507728+lavesh123@users.noreply.github.com> Date: Tue, 27 Oct 2020 09:16:14 +0530 Subject: [PATCH 02/35] Create app.py --- app.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 app.py diff --git a/app.py b/app.py new file mode 100644 index 00000000..2e81b2c5 --- /dev/null +++ b/app.py @@ -0,0 +1,14 @@ +https://l.facebook.com/l.php?u=https%3A%2F%2Fyoutu.be%2Fx084tfX4JnI&h=AT2gLFPQbcNlr2ljUlsqaNCozYpjE9YFCh8o_fysBPR2mEAD6rTxE_ayoY23DFNFfrvSqQ6EktuRm_uORUI8aq9jO_TgtjfoE5BEy00IKwD4fJR2Flx1Deph0pH7MUThbBev_5XAG2xRFnJ5c10f&s=1 +def isArmstrong(x): + + n = order(x) + temp = x + sum1 = 0 + + while (temp != 0): + r = temp % 10 + sum1 = sum1 + power(r, n) + temp = temp // 10 + + # If condition satisfies + return (sum1 == x) From e6c481866410dc90bcf3b8e2085e9bcebb4cad2f Mon Sep 17 00:00:00 2001 From: Rohit Guati Date: Tue, 27 Oct 2020 11:46:52 +0530 Subject: [PATCH 03/35] Create json2csv.py --- json2csv.py | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 json2csv.py diff --git a/json2csv.py b/json2csv.py new file mode 100644 index 00000000..bbc3c8f9 --- /dev/null +++ b/json2csv.py @@ -0,0 +1,3 @@ +import pandas as pd +df = pd.read_json (r'C:\\Users\\Rohit\\Desktop\\JSON\\0.json') +df.to_csv (r'C:\\Users\\Rohit\\Desktop\\JSON\\0.csv', index = None) From b71f1af408f0545c304ae19188dad6cae59ca50a Mon Sep 17 00:00:00 2001 From: ahtazaz <57252754+ahtazaz@users.noreply.github.com> Date: Tue, 27 Oct 2020 16:04:11 +0500 Subject: [PATCH 04/35] Create quadraticEquation.py --- quadraticEquation.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 quadraticEquation.py diff --git a/quadraticEquation.py b/quadraticEquation.py new file mode 100644 index 00000000..bcfb2c6e --- /dev/null +++ b/quadraticEquation.py @@ -0,0 +1,14 @@ +#https://web.facebook.com/permalink.php?story_fbid=994669841008275&id=100013958058927 +import math + +a = 1 +b = 5 +c = 6 + +# calculate the discriminant +d = (b**2) - (4*a*c) + +sol1 = (-b-cmath.sqrt(d))/(2*a) +sol2 = (-b+cmath.sqrt(d))/(2*a) + +print('The solution are {0} and {1}'.format(sol1,sol2)) From ab9899b01950fb17090928344aaf1f6b49c5ac9b Mon Sep 17 00:00:00 2001 From: anant-cyber <56481173+anant-cyber@users.noreply.github.com> Date: Tue, 27 Oct 2020 21:03:21 +0530 Subject: [PATCH 05/35] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c1f8d08c..794ac2d3 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # subscribed jay vijay # Python-Programs -python program for live corona graph +python program for live corona graph. import pandas as pd From bdf97653069cfe1de46cb81e9237621974d4104b Mon Sep 17 00:00:00 2001 From: utkxxrsh <64093818+utkxxrsh@users.noreply.github.com> Date: Wed, 28 Oct 2020 22:21:10 +0530 Subject: [PATCH 06/35] Create HourGlass.py --- HourGlass.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 HourGlass.py diff --git a/HourGlass.py b/HourGlass.py new file mode 100644 index 00000000..49275c33 --- /dev/null +++ b/HourGlass.py @@ -0,0 +1,19 @@ +import sys + + +a = [] +for arr_i in range(6): + arr_t = [int(arr_temp) for arr_temp in input().strip().split(' ')] + a.append(arr_t) + +sumslist = [] + +def calculatesum(i,j): + return(a[i][j] + a[i][j+1] + a[i][j+2] + a[i+1][j+1] + a[i+2][j] + a[i+2][j+1] + a[i+2][j+2]) + +for j in range(0,4): + for i in range(0,4): + sum = calculatesum(i,j) + sumslist.append(sum) + +print(max(sumslist)) From 48a38ff65980a1d4c6a3b07b6f708e3f143b2784 Mon Sep 17 00:00:00 2001 From: Rohit Guati Date: Thu, 29 Oct 2020 16:51:59 +0530 Subject: [PATCH 07/35] Create json2pcd.py --- json2pcd.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 json2pcd.py diff --git a/json2pcd.py b/json2pcd.py new file mode 100644 index 00000000..d0a54b37 --- /dev/null +++ b/json2pcd.py @@ -0,0 +1,28 @@ +import json + + +for count in range(4): + + pathIn = "C:\\Users\\Rohit\\Downloads\\jsontry\\" + str(count) +".json" + pathOut = "C:\\Users\\Rohit\\Desktop\\Output\\"+ str(count) +".json" + + path_to_input = pathIn + path_to_output = pathOut + + with open(path_to_input) as json_file: + data_read =json.loads(json_file.read()) + + data_write = [] + points_json = {} + + for pts in data_read['points']: + data = {}; + row = str(pts['x']) + " " + str(pts['y']) + " " + str(pts['z']) + " " + str(int(pts['i'])) + data = row + + data_write.append(data) + + + with open(path_to_output, 'w') as write_json_file: + json.dump(data_write,write_json_file, indent =4) + print(len(data_read)) From b240f165df63ad7cd450c78328d748695105b16f Mon Sep 17 00:00:00 2001 From: Rohit Guati Date: Thu, 29 Oct 2020 16:54:46 +0530 Subject: [PATCH 08/35] Create bin2ascii.py --- bin2ascii.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 bin2ascii.py diff --git a/bin2ascii.py b/bin2ascii.py new file mode 100644 index 00000000..cbc2fc02 --- /dev/null +++ b/bin2ascii.py @@ -0,0 +1,13 @@ +import binascii + +text = "Simply Easy Learning" + +# Converting binary to ascii +data_b2a = binascii.b2a_uu(text) +print "**Binary to Ascii** \n" +print data_b2a + +# Converting back from ascii to binary +data_a2b = binascii.a2b_uu(data_b2a) +print "**Ascii to Binary** \n" +print data_a2b From d0465d1834cd0c48f213b0e3a16d841727b120a4 Mon Sep 17 00:00:00 2001 From: Utkarsh Deep <64093818+utkxxrsh@users.noreply.github.com> Date: Thu, 29 Oct 2020 17:27:24 +0530 Subject: [PATCH 09/35] Create SecondHighestScore.py --- SecondHighestScore.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 SecondHighestScore.py diff --git a/SecondHighestScore.py b/SecondHighestScore.py new file mode 100644 index 00000000..785be262 --- /dev/null +++ b/SecondHighestScore.py @@ -0,0 +1,33 @@ +students = [] +score_list = [] + +for _ in range(int(input())): + + temp = [] + + name = input() + score = float(input()) + + temp.append(name) + temp.append(score) + + score_list.append(score) + students.append(temp) + +score_list = list(dict.fromkeys(score_list)) +score_list.sort() + +if len(students) >= 2: + second_lowest_students = [] + second_lowest_score = score_list[1] + + for i in students: + if second_lowest_score in i: + # print(i[0]) + second_lowest_students.append(i[0]) + else: + pass + print('\n'.join(sorted(second_lowest_students, key=lambda second_lowest_students: second_lowest_students))) + +else: + print(students[0][0]) From a873649293ee7fb07f398346ac48394008c81891 Mon Sep 17 00:00:00 2001 From: sukarna jana <47217084+Sukarnascience@users.noreply.github.com> Date: Fri, 30 Oct 2020 10:29:12 +0530 Subject: [PATCH 10/35] Added .Py Code which will convert video2audio file it will help to convert the video file and take the audio track and create a new audio file --- Video2AudioConverter.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Video2AudioConverter.py diff --git a/Video2AudioConverter.py b/Video2AudioConverter.py new file mode 100644 index 00000000..2cd6cbe5 --- /dev/null +++ b/Video2AudioConverter.py @@ -0,0 +1,24 @@ +#https://www.facebook.com/sukarna.jana.9/posts/861280437944655 +#Subscribed by Sukarna Jana + +import imageio +import moviepy.editor + +def convert(aa='import.mp4',bb='export.mp3'): + aa=(r'{}'.format(a)) + bb=(r'{}'.format(b)) + video=moviepy.editor.VideoFileClip(aa) + audio=video.audio + audio.write_audiofile(bb) + print('converted successfully') + +if __name__=="__main__": + print(r"Enter the path of your video file:- eg:-C:\Users\VAIO\Desktop\IMPORT.mp4 or press enter") + a=str(input("path:---")) + print(r"Enter the path of your audio file should be expoted with name of the audio file:- eg:-C:\Users\VAIO\Desktop\EXPORT.mp3 or press enter") + b=str(input("path:---")) + if(a=='' or None and b=='' or None): + convert() + else: + convert(a,b) + From 431f43c6a31246c4a7ff310a53767d1119ea9c96 Mon Sep 17 00:00:00 2001 From: sukarna jana <47217084+Sukarnascience@users.noreply.github.com> Date: Fri, 30 Oct 2020 10:38:29 +0530 Subject: [PATCH 11/35] Added a .py file to unzip the zip file to run this code install module using pip install zipfile36 / pip install zipfile37 --- zip2unzip.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 zip2unzip.py diff --git a/zip2unzip.py b/zip2unzip.py new file mode 100644 index 00000000..a98b22d1 --- /dev/null +++ b/zip2unzip.py @@ -0,0 +1,18 @@ +#https://www.facebook.com/sukarna.jana.9/posts/861280437944655 +#Subscribed by Sukarna Jana + +#install module using pip install zipfile36 / pip install zipfile37 +from zipfile import ZipFile as zf + +#specifying the zip file name or path +# we are using \\ because we are running code in python 3.8.1 +file_name="C:\\Users\\VAIO\\Desktop\\Raspbian_TempGUI-master.zip" + +#opening the zip file in read mode +with zf(file_name,'r') as zip: + # printing all the contents of the zip file + zip.printdir() + # extracting all the files + print('Extracting files, please wait processing....') + zip.extractall() + print('Done!') From 5407c38f0d22e8dac39c04d91eb5a198e70f39da Mon Sep 17 00:00:00 2001 From: sukarna jana <47217084+Sukarnascience@users.noreply.github.com> Date: Fri, 30 Oct 2020 10:50:42 +0530 Subject: [PATCH 12/35] Added a .py code of slam book This code uses MySQL for storing the data And for the GUI mode the I am using Tkinter --- SlamBook.py | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 SlamBook.py diff --git a/SlamBook.py b/SlamBook.py new file mode 100644 index 00000000..647c2ec7 --- /dev/null +++ b/SlamBook.py @@ -0,0 +1,78 @@ +#https://www.facebook.com/sukarna.jana.9/posts/861280437944655 +#Subscribed by Sukarna Jana + +import mysql.connector as sql +from tkinter import * +from tkinter import messagebox +import time + +screen=Tk() + +screen.title("Insert Data") +screen.geometry("500x500") + +FN=StringVar() +LN=StringVar() +SEX=StringVar() +RS=StringVar() +PN=IntVar() + +def put(): + datafrom=sql.connect(host='localhost',passwd='jana',user='root',database='py_project') + #insert Your details in the place of host,passwd,user,database + A=FN.get() + B=LN.get() + C=SEX.get() + D=RS.get() + E=PN.get() + + cc=datafrom.cursor() + cc.execute("INSERT INTO friends values(0,'{}','{}','{}','{}',{});".format(A,B,C,D,float(E))) + datafrom.commit() + cc.execute("select * from friends;") + print(cc.fetchall()) + datafrom.close() + +l1=Label(text="Welcome To s.jana Data") +l1.pack() +l2=Label(text="____________________________________________") +l2.pack() + +l3=Label(text="First Name :") +l3.place(x=100,y=50) +e1=Entry(screen,textvariable=FN) +e1.place(x=200,y=50) + +l4=Label(text="Last Name :") +l4.place(x=100,y=100) +e2=Entry(screen,textvariable=LN) +e2.place(x=200,y=100) + +l5=Label(text="SEX :") +l5.place(x=100,y=150) +e3=Entry(screen,textvariable=SEX) +e3.place(x=200,y=150) + +l6=Label(text="Relationship :") +l6.place(x=100,y=200) +e4=Entry(screen,textvariable=RS) +e4.place(x=200,y=200) + +l7=Label(text="Phone No. :") +l7.place(x=100,y=250) +e5=Entry(screen,textvariable=PN) +e5.place(x=200,y=250) + +def end(): + screen.destroy() +def nextp(): + put() + messagebox.showinfo("Thank You","Thank You, Loaded in DataBase :-) ") + + +b1=Button(text="Cancel",command=end) +b1.place(x=300,y=300) +b2=Button(text="Next->",command=nextp) +b2.place(x=400,y=300) +screen.mainloop() + From ee5aa9bd3b8cb1674e5936ac5c55bd1b06ff22cb Mon Sep 17 00:00:00 2001 From: sukarna jana <47217084+Sukarnascience@users.noreply.github.com> Date: Fri, 30 Oct 2020 10:57:58 +0530 Subject: [PATCH 13/35] Added a .py code for computer vision its use CV2 --- ComputerVision.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 ComputerVision.py diff --git a/ComputerVision.py b/ComputerVision.py new file mode 100644 index 00000000..4bc61e03 --- /dev/null +++ b/ComputerVision.py @@ -0,0 +1,14 @@ +#https://www.facebook.com/sukarna.jana.9/posts/861280437944655 +#Subscribed by Sukarna Jana + +import cv2 +vid = cv2.VideoCapture(0) +while(True): + + ret, frame = vid.read() + cv2.imshow('frame', frame) + if cv2.waitKey(1) & 0xFF == ord('q'): + break +vid.release() +cv2.destroyAllWindows() + From 33d7ce601701832ff6aa771b846c6e2d6179083d Mon Sep 17 00:00:00 2001 From: maheshdbabar9340 <53929423+maheshdbabar9340@users.noreply.github.com> Date: Fri, 30 Oct 2020 21:42:03 +0530 Subject: [PATCH 14/35] Added File for Distributed Database. --- Query Processing For Distributed Database.py | 64 ++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Query Processing For Distributed Database.py diff --git a/Query Processing For Distributed Database.py b/Query Processing For Distributed Database.py new file mode 100644 index 00000000..8c930bb7 --- /dev/null +++ b/Query Processing For Distributed Database.py @@ -0,0 +1,64 @@ +no = int(input("Enter the total no of sites")) +result_site = int(input("Enter the result site")) +A = [None] * (no+1) +B = [] +strategies = [] +strategy = 0 + +# Accept data information for each site(check for availability) + +for i in range(1, no+1): + available = input("Is data for this site available ? Enter y or n") + + if(available == "y"): + nooftuples = int(input("Enter no of tuples")) + size = int(input("Enter size of each tuple")) + + data_size = nooftuples*size + A[i] = data_size + + else: + A[i] = 0 + +# Accept result relation data + +print("** Enter Result Site Data ***") +nooftuples = int(input("Enter no of tuples")) +size = int(input("Enter size of each tuple")) +result_data = nooftuples * size + +# Find total strategies and calculate data transfer for each strategy +print("** PROCESSING ***") + +for i in range(1, no+1): + (total_data, total_data_transfer) = (0, 0) + + if(i == result_site): + for j in range(1, no+1): + if(j != result_site): + print("Transfer data from site ",j," to site ",result_site) + total_data += A[j] + strategy += 1 + print("Strategy Id:", strategy) + print("Total Data Transfer:", total_data) + B.append(total_data) + strategies.append(strategy) + + else: + for k in range(1, no+1): + if(k != i): + print("Transfer data from site ",k," to site ",i) + total_data += A[k] + + total_data_transfer = total_data + result_data + strategy += 1 + B.append(total_data_transfer) + strategies.append(strategy) + + print("Strategy Id:", strategy) + print("Total Data Transfer:", total_data_transfer) + +print("** ENDED ***") + +print("Min data transfer", min(B)) +print("Best strategy", strategies[B.index(min(B))]) From c0c415c3dbd42b1496593aa55d68e93a4bc0e189 Mon Sep 17 00:00:00 2001 From: Tanishq More <44018380+tanishq-1011@users.noreply.github.com> Date: Fri, 30 Oct 2020 23:46:01 +0530 Subject: [PATCH 15/35] update calculator.py --- calculator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/calculator.py b/calculator.py index 09ec3bd7..dff72cc6 100644 --- a/calculator.py +++ b/calculator.py @@ -11,7 +11,7 @@ def multiply(x, y): # This function divides two numbers def divide(x, y): - return x / y + return int(x / y) print("Select operation.") From eae41d536fee3f98e005d070c396c86042935f72 Mon Sep 17 00:00:00 2001 From: Tanishq More <44018380+tanishq-1011@users.noreply.github.com> Date: Fri, 30 Oct 2020 23:54:52 +0530 Subject: [PATCH 16/35] update fibo.py --- fibonacci.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fibonacci.py b/fibonacci.py index d2b65687..07c4d3c1 100644 --- a/fibonacci.py +++ b/fibonacci.py @@ -2,7 +2,8 @@ nterms = int(input("How many terms? ")) # first two terms -n1, n2 = 0, 1 +n1 = 0 +n2=1 count = 0 # check if the number of terms is valid From 074271554dcedd8224899f22139d66e6b5b77803 Mon Sep 17 00:00:00 2001 From: Tanishq More <44018380+tanishq-1011@users.noreply.github.com> Date: Sat, 31 Oct 2020 10:24:48 +0530 Subject: [PATCH 17/35] update rand.py --- Generate a random number | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Generate a random number b/Generate a random number index 53813f9c..d917662b 100644 --- a/Generate a random number +++ b/Generate a random number @@ -4,6 +4,6 @@ # Program to generate a random number between 0 and 9 # importing the random module -import random +import numpy as np -print(random.randint(0,9)) +print(np.random.randint(0,9)) From 6249bcc8f702bef0feacfdf230f22a7a8306cdb3 Mon Sep 17 00:00:00 2001 From: Tanishq More <44018380+tanishq-1011@users.noreply.github.com> Date: Sat, 31 Oct 2020 10:28:06 +0530 Subject: [PATCH 18/35] create login_gui.py --- login gui.py | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 login gui.py diff --git a/login gui.py b/login gui.py new file mode 100644 index 00000000..69ec1eeb --- /dev/null +++ b/login gui.py @@ -0,0 +1,97 @@ +from tkinter import * +import os + +creds = 'tempfile.temp' # This just sets the variable creds to 'tempfile.temp' + +def Signup(): # This is the signup definition, + global pwordE # These globals just make the variables global to the entire script, meaning any definition can use them + global nameE + global roots + + roots = Tk() # This creates the window, just a blank one. + roots.title('Signup') # This renames the title of said window to 'signup' + intruction = Label(roots, text='Please Enter new Credidentials\n') # This puts a label, so just a piece of text saying 'please enter blah' + intruction.grid(row=0, column=0, sticky=E) # This just puts it in the window, on row 0, col 0. If you want to learn more look up a tkinter tutorial :) + + nameL = Label(roots, text='New Username: ') # This just does the same as above, instead with the text new username. + pwordL = Label(roots, text='New Password: ') # ^^ + nameL.grid(row=1, column=0, sticky=W) # Same thing as the instruction var just on different rows. :) Tkinter is like that. + pwordL.grid(row=2, column=0, sticky=W) # ^^ + + nameE = Entry(roots) # This now puts a text box waiting for input. + pwordE = Entry(roots, show='*') # Same as above, yet 'show="*"' What this does is replace the text with *, like a password box :D + nameE.grid(row=1, column=1) # You know what this does now :D + pwordE.grid(row=2, column=1) # ^^ + + signupButton = Button(roots, text='Signup', command=FSSignup) # This creates the button with the text 'signup', when you click it, the command 'fssignup' will run. which is the def + signupButton.grid(columnspan=2, sticky=W) + roots.mainloop() # This just makes the window keep open, we will destroy it soon + +def FSSignup(): + with open(creds, 'w') as f: # Creates a document using the variable we made at the top. + f.write(nameE.get()) # nameE is the variable we were storing the input to. Tkinter makes us use .get() to get the actual string. + f.write('\n') # Splits the line so both variables are on different lines. + f.write(pwordE.get()) # Same as nameE just with pword var + f.close() # Closes the file + + roots.destroy() # This will destroy the signup window. :) + Login() # This will move us onto the login definition :D + +def Login(): + global nameEL + global pwordEL # More globals :D + global rootA + + rootA = Tk() # This now makes a new window. + rootA.title('Login') # This makes the window title 'login' + + intruction = Label(rootA, text='Please Login\n') # More labels to tell us what they do + intruction.grid(sticky=E) # Blahdy Blah + + nameL = Label(rootA, text='Username: ') # More labels + pwordL = Label(rootA, text='Password: ') # ^ + nameL.grid(row=1, sticky=W) + pwordL.grid(row=2, sticky=W) + + nameEL = Entry(rootA) # The entry input + pwordEL = Entry(rootA, show='*') + nameEL.grid(row=1, column=1) + pwordEL.grid(row=2, column=1) + + loginB = Button(rootA, text='Login', command=CheckLogin) # This makes the login button, which will go to the CheckLogin def. + loginB.grid(columnspan=2, sticky=W) + + rmuser = Button(rootA, text='Delete User', fg='red', command=DelUser) # This makes the deluser button. blah go to the deluser def. + rmuser.grid(columnspan=2, sticky=W) + rootA.mainloop() + +def CheckLogin(): + with open(creds) as f: + data = f.readlines() # This takes the entire document we put the info into and puts it into the data variable + uname = data[0].rstrip() # Data[0], 0 is the first line, 1 is the second and so on. + pword = data[1].rstrip() # Using .rstrip() will remove the \n (new line) word from before when we input it + + if nameEL.get() == uname and pwordEL.get() == pword: # Checks to see if you entered the correct data. + r = Tk() # Opens new window + r.title(':D') + r.geometry('150x50') # Makes the window a certain size + rlbl = Label(r, text='\n[+] Logged In') # "logged in" label + rlbl.pack() # Pack is like .grid(), just different + r.mainloop() + else: + r = Tk() + r.title('D:') + r.geometry('150x50') + rlbl = Label(r, text='\n[!] Invalid Login') + rlbl.pack() + r.mainloop() + +def DelUser(): + os.remove(creds) # Removes the file + rootA.destroy() # Destroys the login window + Signup() # And goes back to the start! + +if os.path.isfile(creds): + Login() +else: # This if else statement checks to see if the file exists. If it does it will go to Login, if not it will go to Signup :) + Signup() From 849b51b18c75f0a1ae804dce8ffb1a3118722dfe Mon Sep 17 00:00:00 2001 From: rutuja1409 <43930006+rutuja1409@users.noreply.github.com> Date: Sat, 31 Oct 2020 17:54:22 +0530 Subject: [PATCH 19/35] Created turtle.py --- turtle.py | 369 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 369 insertions(+) create mode 100644 turtle.py diff --git a/turtle.py b/turtle.py new file mode 100644 index 00000000..5d6a12a2 --- /dev/null +++ b/turtle.py @@ -0,0 +1,369 @@ +import turtle + +mitul=turtle.Turtle() +mitul.width(8) +mitul.color("red") +new=turtle.getscreen() +mitul.speed(4) + +new.bgcolor("lightblue") + +# Hidden Work(penup) +mitul.left(180) +mitul.penup() +mitul.forward(300) +mitul.right(90) +mitul.forward(100) +mitul.pendown() + +# Printing H + + +#start to draw +mitul.forward(50) +mitul.right(90) +mitul.forward(50) +mitul.left(90) +mitul.forward(50) +mitul.left(90) + +mitul.penup() +mitul.forward(50) +mitul.left(90) +mitul.pendown() +mitul.forward(50) +mitul.left(90) +mitul.forward(50) +mitul.right(90) +mitul.forward(50) + + +# printing A + +mitul.penup() +mitul.left(90) +mitul.forward(15) +mitul.pendown() +mitul.left(70) +mitul.forward(110) +mitul.right(70) +mitul.right(70) +mitul.forward(110) +mitul.left(180) +mitul.forward(55) +mitul.left(70) +mitul.forward(38) +mitul.left(70) +mitul.penup() +mitul.forward(55) +mitul.left(110) + +mitul.forward(100) + +# printing P + +mitul.left(90) +mitul.pendown() +mitul.forward(100) +mitul.right(90) +mitul.forward(50) +mitul.right(20) +mitul.forward(20) +mitul.right(70) +mitul.forward(40) +mitul.right(70) +mitul.forward(20) +mitul.right(20) +mitul.forward(50) +mitul.left(90) +mitul.forward(50) +mitul.left(90) +mitul.penup() +mitul.forward(100) + + +# printing P + +mitul.left(90) +mitul.pendown() +mitul.forward(100) +mitul.right(90) +mitul.forward(50) +mitul.right(20) +mitul.forward(20) +mitul.right(70) +mitul.forward(40) +mitul.right(70) +mitul.forward(20) +mitul.right(20) +mitul.forward(50) +mitul.left(90) +mitul.forward(50) +mitul.left(90) +mitul.penup() +mitul.forward(100) + +# printing Y + +mitul.forward(20) +mitul.pendown() +mitul.left(90) +mitul.forward(50) +mitul.left(30) +mitul.forward(60) +mitul.backward(60) +mitul.right(60) +mitul.forward(60) +mitul.backward(60) +mitul.left(30) + +# go to Home + +mitul.penup() +mitul.home() + +mitul.color("orange") +new.bgcolor("lightgreen") +# setting second row + +mitul.backward(300) +mitul.right(90) +mitul.forward(60) +mitul.left(180) + + +# printing P + + +mitul.pendown() +mitul.forward(100) +mitul.right(90) +mitul.forward(50) +mitul.right(20) +mitul.forward(20) +mitul.right(70) +mitul.forward(40) +mitul.right(70) +mitul.forward(20) +mitul.right(20) +mitul.forward(50) +mitul.backward(50) +mitul.left(180) +mitul.right(20) +mitul.forward(20) +mitul.right(70) +mitul.forward(40) +mitul.right(70) +mitul.forward(20) +mitul.right(20) +mitul.forward(50) +mitul.right(90) +mitul.forward(10) + + +# go to Home + +mitul.penup() +mitul.home() + +# setting up + +mitul.backward(200) +mitul.right(90) +mitul.forward(10) +mitul.left(90) +mitul.pendown() +mitul.forward(20) +mitul.penup() +mitul.home() + +# D + +mitul.backward(150) +mitul.right(90) +mitul.forward(60) +mitul.pendown() +mitul.backward(100) +mitul.right(90) +mitul.forward(10) +mitul.backward(70) +mitul.left(180) +mitul.right(20) +mitul.forward(20) +mitul.right(70) +mitul.forward(88) +mitul.right(70) +mitul.forward(20) +mitul.right(20) +mitul.forward(70) + +mitul.penup() +mitul.home() + +# set up for A + +mitul.backward(50) +mitul.right(90) +mitul.forward(65) +mitul.left(90) + + + +# printing A + + +mitul.pendown() +mitul.left(70) +mitul.forward(110) +mitul.right(70) +mitul.right(70) +mitul.forward(110) +mitul.left(180) +mitul.forward(55) +mitul.left(70) +mitul.forward(38) +mitul.left(70) +mitul.penup() +mitul.forward(55) +mitul.left(110) + +mitul.forward(100) + +# printing Y + + +# printing Y + + +mitul.pendown() +mitul.left(90) +mitul.forward(50) +mitul.left(30) +mitul.forward(60) +mitul.backward(60) +mitul.right(60) +mitul.forward(60) +mitul.backward(60) +mitul.left(30) + +# go to Home + +mitul.penup() +mitul.home() + + +# settig pogition + +mitul.right(90) +mitul.forward(215) +mitul.right(90) +mitul.forward(200) +mitul.right(90) + +#color + +mitul.color("green") +new.bgcolor("lightblue") + + +#printing Pooja + + +# printing P + + +mitul.pendown() +mitul.forward(100) +mitul.right(90) +mitul.forward(50) +mitul.right(20) +mitul.forward(20) +mitul.right(70) +mitul.forward(40) +mitul.right(70) +mitul.forward(20) +mitul.right(20) +mitul.forward(50) +mitul.backward(50) +mitul.left(180) +mitul.penup() + +# printing A + + +mitul.pendown() +mitul.left(70) +mitul.forward(110) +mitul.right(70) +mitul.right(70) +mitul.forward(110) +mitul.left(180) +mitul.forward(55) +mitul.left(70) +mitul.forward(38) +mitul.left(70) +mitul.penup() +mitul.forward(55) +mitul.left(110) + +mitul.forward(100) + + + +# printing Y + + +mitul.pendown() +mitul.left(90) +mitul.forward(50) +mitul.left(30) +mitul.forward(60) +mitul.backward(60) +mitul.right(60) +mitul.forward(60) +mitul.backward(60) +mitul.left(30) + + +# setup +mitul.penup() +mitul.left(90) +mitul.forward(80) +mitul.left(90) +mitul.forward(7) + + + +# design + + +#design pattern +mitul.home() +mitul.forward(200) +mitul.pendown() +mitul.color("red") +mitul.width(3) +mitul.speed(0) + +def squre(length, angle): + + mitul.forward(length) + mitul.right(angle) + mitul.forward(length) + mitul.right(angle) + + mitul.forward(length) + mitul.right(angle) + mitul.forward(length) + mitul.right(angle) + +squre(80, 90) + +for i in range(36): + mitul.right(10) + squre(80, 90) + + + + +turtle.mainloop() From 591ddf6906cae1bd7e1597c7833881aa7a74b6da Mon Sep 17 00:00:00 2001 From: rutuja1409 <43930006+rutuja1409@users.noreply.github.com> Date: Sat, 31 Oct 2020 17:57:00 +0530 Subject: [PATCH 20/35] Created tictactoe.py --- tictactoe.py | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 tictactoe.py diff --git a/tictactoe.py b/tictactoe.py new file mode 100644 index 00000000..2fa21e74 --- /dev/null +++ b/tictactoe.py @@ -0,0 +1,116 @@ +from tkinter import * +import tkinter.messagebox +tk = Tk() +tk.title("Tic Tac Toe") + +pa = StringVar() +playerb = StringVar() +p1 = StringVar() +p2 = StringVar() + +player1_name = Entry(tk, textvariable=p1, bd=5) +player1_name.grid(row=1, column=1, columnspan=8) +player2_name = Entry(tk, textvariable=p2, bd=5) +player2_name.grid(row=2, column=1, columnspan=8) + +bclick = True +flag = 0 + +def disableButton(): + button1.configure(state=DISABLED) + button2.configure(state=DISABLED) + button3.configure(state=DISABLED) + button4.configure(state=DISABLED) + button5.configure(state=DISABLED) + button6.configure(state=DISABLED) + button7.configure(state=DISABLED) + button8.configure(state=DISABLED) + button9.configure(state=DISABLED) + + + +def btnClick(buttons): + global bclick, flag, player2_name, player1_name, playerb, pa + if buttons["text"] == " " and bclick == True: + buttons["text"] = "X" + bclick = False + playerb = p2.get() + " Wins!" + pa = p1.get() + " Wins!" + checkForWin() + flag += 1 + + + elif buttons["text"] == " " and bclick == False: + buttons["text"] = "O" + bclick = True + checkForWin() + flag += 1 + else: + tkinter.messagebox.showinfo("Tic-Tac-Toe", "Button already Clicked!") + +def checkForWin(): + if (button1['text'] == 'X' and button2['text'] == 'X' and button3['text'] == 'X' or + button4['text'] == 'X' and button5['text'] == 'X' and button6['text'] == 'X' or + button7['text'] =='X' and button8['text'] == 'X' and button9['text'] == 'X' or + button1['text'] == 'X' and button5['text'] == 'X' and button9['text'] == 'X' or + button3['text'] == 'X' and button5['text'] == 'X' and button7['text'] == 'X' or + button1['text'] == 'X' and button2['text'] == 'X' and button3['text'] == 'X' or + button1['text'] == 'X' and button4['text'] == 'X' and button7['text'] == 'X' or + button2['text'] == 'X' and button5['text'] == 'X' and button8['text'] == 'X' or + button7['text'] == 'X' and button6['text'] == 'X' and button9['text'] == 'X'): + disableButton() + tkinter.messagebox.showinfo("Tic-Tac-Toe", pa) + + elif(flag == 8): + tkinter.messagebox.showinfo("Tic-Tac-Toe", "It is a Tie") + + elif (button1['text'] == 'O' and button2['text'] == 'O' and button3['text'] == 'O' or + button4['text'] == 'O' and button5['text'] == 'O' and button6['text'] == 'O' or + button7['text'] == 'O' and button8['text'] == 'O' and button9['text'] == 'O' or + button1['text'] == 'O' and button5['text'] == 'O' and button9['text'] == 'O' or + button3['text'] == 'O' and button5['text'] == 'O' and button7['text'] == 'O' or + button1['text'] == 'O' and button2['text'] == 'O' and button3['text'] == 'O' or + button1['text'] == 'O' and button4['text'] == 'O' and button7['text'] == 'O' or + button2['text'] == 'O' and button5['text'] == 'O' and button8['text'] == 'O' or + button7['text'] == 'O' and button6['text'] == 'O' and button9['text'] == 'O'): + disableButton() + tkinter.messagebox.showinfo("Tic-Tac-Toe", playerb) + + +buttons = StringVar() + +label = Label( tk, text="RUTUJA (Type X):", font='Times 12 bold', bg='white', fg='black', height=1, width=15) +label.grid(row=1, column=0) + + +label = Label( tk, text="TANISHQ (Type O):", font='Times 12 bold', bg='white', fg='black', height=1, width=15) +label.grid(row=2, column=0) + +button1 = Button(tk, text=" ", font='Times 20 bold', bg='gray', fg='white', height=4, width=8, command=lambda: btnClick(button1)) +button1.grid(row=3, column=0) + +button2 = Button(tk, text=' ', font='Times 20 bold', bg='gray', fg='white', height=4, width=8, command=lambda: btnClick(button2)) +button2.grid(row=3, column=1) + +button3 = Button(tk, text=' ',font='Times 20 bold', bg='gray', fg='white', height=4, width=8, command=lambda: btnClick(button3)) +button3.grid(row=3, column=2) + +button4 = Button(tk, text=' ', font='Times 20 bold', bg='gray', fg='white', height=4, width=8, command=lambda: btnClick(button4)) +button4.grid(row=4, column=0) + +button5 = Button(tk, text=' ', font='Times 20 bold', bg='gray', fg='white', height=4, width=8, command=lambda: btnClick(button5)) +button5.grid(row=4, column=1) + +button6 = Button(tk, text=' ', font='Times 20 bold', bg='gray', fg='white', height=4, width=8, command=lambda: btnClick(button6)) +button6.grid(row=4, column=2) + +button7 = Button(tk, text=' ', font='Times 20 bold', bg='gray', fg='white', height=4, width=8, command=lambda: btnClick(button7)) +button7.grid(row=5, column=0) + +button8 = Button(tk, text=' ', font='Times 20 bold', bg='gray', fg='white', height=4, width=8, command=lambda: btnClick(button8)) +button8.grid(row=5, column=1) + +button9 = Button(tk, text=' ', font='Times 20 bold', bg='gray', fg='white', height=4, width=8, command=lambda: btnClick(button9)) +button9.grid(row=5, column=2) + +tk.mainloop() From ab488720fdabbc67232fb26941e139b15280df2e Mon Sep 17 00:00:00 2001 From: rutuja1409 <43930006+rutuja1409@users.noreply.github.com> Date: Sat, 31 Oct 2020 17:58:10 +0530 Subject: [PATCH 21/35] Created spaceinvader.py --- spaceinvader.py | 644 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 644 insertions(+) create mode 100644 spaceinvader.py diff --git a/spaceinvader.py b/spaceinvader.py new file mode 100644 index 00000000..96d43ec7 --- /dev/null +++ b/spaceinvader.py @@ -0,0 +1,644 @@ +#!/usr/bin/env python + +# Space Invaders +# Created by Lee Robinson + +from pygame import * +import sys +from os.path import abspath, dirname +from random import choice + +BASE_PATH = abspath(dirname(__file__)) +FONT_PATH = BASE_PATH + '/fonts/' +IMAGE_PATH = BASE_PATH + '/images/' +SOUND_PATH = BASE_PATH + '/sounds/' + +# Colors (R, G, B) +WHITE = (255, 255, 255) +GREEN = (78, 255, 87) +YELLOW = (241, 255, 0) +BLUE = (80, 255, 239) +PURPLE = (203, 0, 255) +RED = (237, 28, 36) + +SCREEN = display.set_mode((800, 600)) +FONT = FONT_PATH + 'space_invaders.ttf' +IMG_NAMES = ['ship', 'mystery', + 'enemy1_1', 'enemy1_2', + 'enemy2_1', 'enemy2_2', + 'enemy3_1', 'enemy3_2', + 'explosionblue', 'explosiongreen', 'explosionpurple', + 'laser', 'enemylaser'] +IMAGES = {name: image.load(IMAGE_PATH + '{}.png'.format(name)).convert_alpha() + for name in IMG_NAMES} + +BLOCKERS_POSITION = 450 +ENEMY_DEFAULT_POSITION = 65 # Initial value for a new game +ENEMY_MOVE_DOWN = 35 + + +class Ship(sprite.Sprite): + def __init__(self): + sprite.Sprite.__init__(self) + self.image = IMAGES['ship'] + self.rect = self.image.get_rect(topleft=(375, 540)) + self.speed = 5 + + def update(self, keys, *args): + if keys[K_LEFT] and self.rect.x > 10: + self.rect.x -= self.speed + if keys[K_RIGHT] and self.rect.x < 740: + self.rect.x += self.speed + game.screen.blit(self.image, self.rect) + + +class Bullet(sprite.Sprite): + def __init__(self, xpos, ypos, direction, speed, filename, side): + sprite.Sprite.__init__(self) + self.image = IMAGES[filename] + self.rect = self.image.get_rect(topleft=(xpos, ypos)) + self.speed = speed + self.direction = direction + self.side = side + self.filename = filename + + def update(self, keys, *args): + game.screen.blit(self.image, self.rect) + self.rect.y += self.speed * self.direction + if self.rect.y < 15 or self.rect.y > 600: + self.kill() + + +class Enemy(sprite.Sprite): + def __init__(self, row, column): + sprite.Sprite.__init__(self) + self.row = row + self.column = column + self.images = [] + self.load_images() + self.index = 0 + self.image = self.images[self.index] + self.rect = self.image.get_rect() + + def toggle_image(self): + self.index += 1 + if self.index >= len(self.images): + self.index = 0 + self.image = self.images[self.index] + + def update(self, *args): + game.screen.blit(self.image, self.rect) + + def load_images(self): + images = {0: ['1_2', '1_1'], + 1: ['2_2', '2_1'], + 2: ['2_2', '2_1'], + 3: ['3_1', '3_2'], + 4: ['3_1', '3_2'], + } + img1, img2 = (IMAGES['enemy{}'.format(img_num)] for img_num in + images[self.row]) + self.images.append(transform.scale(img1, (40, 35))) + self.images.append(transform.scale(img2, (40, 35))) + + +class EnemiesGroup(sprite.Group): + def __init__(self, columns, rows): + sprite.Group.__init__(self) + self.enemies = [[None] * columns for _ in range(rows)] + self.columns = columns + self.rows = rows + self.leftAddMove = 0 + self.rightAddMove = 0 + self.moveTime = 600 + self.direction = 1 + self.rightMoves = 30 + self.leftMoves = 30 + self.moveNumber = 15 + self.timer = time.get_ticks() + self.bottom = game.enemyPosition + ((rows - 1) * 45) + 35 + self._aliveColumns = list(range(columns)) + self._leftAliveColumn = 0 + self._rightAliveColumn = columns - 1 + + def update(self, current_time): + if current_time - self.timer > self.moveTime: + if self.direction == 1: + max_move = self.rightMoves + self.rightAddMove + else: + max_move = self.leftMoves + self.leftAddMove + + if self.moveNumber >= max_move: + self.leftMoves = 30 + self.rightAddMove + self.rightMoves = 30 + self.leftAddMove + self.direction *= -1 + self.moveNumber = 0 + self.bottom = 0 + for enemy in self: + enemy.rect.y += ENEMY_MOVE_DOWN + enemy.toggle_image() + if self.bottom < enemy.rect.y + 35: + self.bottom = enemy.rect.y + 35 + else: + velocity = 10 if self.direction == 1 else -10 + for enemy in self: + enemy.rect.x += velocity + enemy.toggle_image() + self.moveNumber += 1 + + self.timer += self.moveTime + + def add_internal(self, *sprites): + super(EnemiesGroup, self).add_internal(*sprites) + for s in sprites: + self.enemies[s.row][s.column] = s + + def remove_internal(self, *sprites): + super(EnemiesGroup, self).remove_internal(*sprites) + for s in sprites: + self.kill(s) + self.update_speed() + + def is_column_dead(self, column): + return not any(self.enemies[row][column] + for row in range(self.rows)) + + def random_bottom(self): + col = choice(self._aliveColumns) + col_enemies = (self.enemies[row - 1][col] + for row in range(self.rows, 0, -1)) + return next((en for en in col_enemies if en is not None), None) + + def update_speed(self): + if len(self) == 1: + self.moveTime = 200 + elif len(self) <= 10: + self.moveTime = 400 + + def kill(self, enemy): + self.enemies[enemy.row][enemy.column] = None + is_column_dead = self.is_column_dead(enemy.column) + if is_column_dead: + self._aliveColumns.remove(enemy.column) + + if enemy.column == self._rightAliveColumn: + while self._rightAliveColumn > 0 and is_column_dead: + self._rightAliveColumn -= 1 + self.rightAddMove += 5 + is_column_dead = self.is_column_dead(self._rightAliveColumn) + + elif enemy.column == self._leftAliveColumn: + while self._leftAliveColumn < self.columns and is_column_dead: + self._leftAliveColumn += 1 + self.leftAddMove += 5 + is_column_dead = self.is_column_dead(self._leftAliveColumn) + + +class Blocker(sprite.Sprite): + def __init__(self, size, color, row, column): + sprite.Sprite.__init__(self) + self.height = size + self.width = size + self.color = color + self.image = Surface((self.width, self.height)) + self.image.fill(self.color) + self.rect = self.image.get_rect() + self.row = row + self.column = column + + def update(self, keys, *args): + game.screen.blit(self.image, self.rect) + + +class Mystery(sprite.Sprite): + def __init__(self): + sprite.Sprite.__init__(self) + self.image = IMAGES['mystery'] + self.image = transform.scale(self.image, (75, 35)) + self.rect = self.image.get_rect(topleft=(-80, 45)) + self.row = 5 + self.moveTime = 25000 + self.direction = 1 + self.timer = time.get_ticks() + self.mysteryEntered = mixer.Sound(SOUND_PATH + 'mysteryentered.wav') + self.mysteryEntered.set_volume(0.3) + self.playSound = True + + def update(self, keys, currentTime, *args): + resetTimer = False + passed = currentTime - self.timer + if passed > self.moveTime: + if (self.rect.x < 0 or self.rect.x > 800) and self.playSound: + self.mysteryEntered.play() + self.playSound = False + if self.rect.x < 840 and self.direction == 1: + self.mysteryEntered.fadeout(4000) + self.rect.x += 2 + game.screen.blit(self.image, self.rect) + if self.rect.x > -100 and self.direction == -1: + self.mysteryEntered.fadeout(4000) + self.rect.x -= 2 + game.screen.blit(self.image, self.rect) + + if self.rect.x > 830: + self.playSound = True + self.direction = -1 + resetTimer = True + if self.rect.x < -90: + self.playSound = True + self.direction = 1 + resetTimer = True + if passed > self.moveTime and resetTimer: + self.timer = currentTime + + +class EnemyExplosion(sprite.Sprite): + def __init__(self, enemy, *groups): + super(EnemyExplosion, self).__init__(*groups) + self.image = transform.scale(self.get_image(enemy.row), (40, 35)) + self.image2 = transform.scale(self.get_image(enemy.row), (50, 45)) + self.rect = self.image.get_rect(topleft=(enemy.rect.x, enemy.rect.y)) + self.timer = time.get_ticks() + + @staticmethod + def get_image(row): + img_colors = ['purple', 'blue', 'blue', 'green', 'green'] + return IMAGES['explosion{}'.format(img_colors[row])] + + def update(self, current_time, *args): + passed = current_time - self.timer + if passed <= 100: + game.screen.blit(self.image, self.rect) + elif passed <= 200: + game.screen.blit(self.image2, (self.rect.x - 6, self.rect.y - 6)) + elif 400 < passed: + self.kill() + + +class MysteryExplosion(sprite.Sprite): + def __init__(self, mystery, score, *groups): + super(MysteryExplosion, self).__init__(*groups) + self.text = Text(FONT, 20, str(score), WHITE, + mystery.rect.x + 20, mystery.rect.y + 6) + self.timer = time.get_ticks() + + def update(self, current_time, *args): + passed = current_time - self.timer + if passed <= 200 or 400 < passed <= 600: + self.text.draw(game.screen) + elif 600 < passed: + self.kill() + + +class ShipExplosion(sprite.Sprite): + def __init__(self, ship, *groups): + super(ShipExplosion, self).__init__(*groups) + self.image = IMAGES['ship'] + self.rect = self.image.get_rect(topleft=(ship.rect.x, ship.rect.y)) + self.timer = time.get_ticks() + + def update(self, current_time, *args): + passed = current_time - self.timer + if 300 < passed <= 600: + game.screen.blit(self.image, self.rect) + elif 900 < passed: + self.kill() + + +class Life(sprite.Sprite): + def __init__(self, xpos, ypos): + sprite.Sprite.__init__(self) + self.image = IMAGES['ship'] + self.image = transform.scale(self.image, (23, 23)) + self.rect = self.image.get_rect(topleft=(xpos, ypos)) + + def update(self, *args): + game.screen.blit(self.image, self.rect) + + +class Text(object): + def __init__(self, textFont, size, message, color, xpos, ypos): + self.font = font.Font(textFont, size) + self.surface = self.font.render(message, True, color) + self.rect = self.surface.get_rect(topleft=(xpos, ypos)) + + def draw(self, surface): + surface.blit(self.surface, self.rect) + + +class SpaceInvaders(object): + def __init__(self): + # It seems, in Linux buffersize=512 is not enough, use 4096 to prevent: + # ALSA lib pcm.c:7963:(snd_pcm_recover) underrun occurred + mixer.pre_init(44100, -16, 1, 4096) + init() + self.clock = time.Clock() + self.caption = display.set_caption('Space Invaders') + self.screen = SCREEN + self.background = image.load(IMAGE_PATH + 'background.jpg').convert() + self.startGame = False + self.mainScreen = True + self.gameOver = False + # Counter for enemy starting position (increased each new round) + self.enemyPosition = ENEMY_DEFAULT_POSITION + self.titleText = Text(FONT, 50, 'Space Invaders', WHITE, 164, 155) + self.titleText2 = Text(FONT, 25, 'Press any key to continue', WHITE, + 201, 225) + self.gameOverText = Text(FONT, 50, 'Game Over', WHITE, 250, 270) + self.nextRoundText = Text(FONT, 50, 'Next Round', WHITE, 240, 270) + self.enemy1Text = Text(FONT, 25, ' = 10 pts', GREEN, 368, 270) + self.enemy2Text = Text(FONT, 25, ' = 20 pts', BLUE, 368, 320) + self.enemy3Text = Text(FONT, 25, ' = 30 pts', PURPLE, 368, 370) + self.enemy4Text = Text(FONT, 25, ' = ?????', RED, 368, 420) + self.scoreText = Text(FONT, 20, 'Score', WHITE, 5, 5) + self.livesText = Text(FONT, 20, 'Lives ', WHITE, 640, 5) + + self.life1 = Life(715, 3) + self.life2 = Life(742, 3) + self.life3 = Life(769, 3) + self.livesGroup = sprite.Group(self.life1, self.life2, self.life3) + + def reset(self, score): + self.player = Ship() + self.playerGroup = sprite.Group(self.player) + self.explosionsGroup = sprite.Group() + self.bullets = sprite.Group() + self.mysteryShip = Mystery() + self.mysteryGroup = sprite.Group(self.mysteryShip) + self.enemyBullets = sprite.Group() + self.make_enemies() + self.allSprites = sprite.Group(self.player, self.enemies, + self.livesGroup, self.mysteryShip) + self.keys = key.get_pressed() + + self.timer = time.get_ticks() + self.noteTimer = time.get_ticks() + self.shipTimer = time.get_ticks() + self.score = score + self.create_audio() + self.makeNewShip = False + self.shipAlive = True + + def make_blockers(self, number): + blockerGroup = sprite.Group() + for row in range(4): + for column in range(9): + blocker = Blocker(10, GREEN, row, column) + blocker.rect.x = 50 + (200 * number) + (column * blocker.width) + blocker.rect.y = BLOCKERS_POSITION + (row * blocker.height) + blockerGroup.add(blocker) + return blockerGroup + + def create_audio(self): + self.sounds = {} + for sound_name in ['shoot', 'shoot2', 'invaderkilled', 'mysterykilled', + 'shipexplosion']: + self.sounds[sound_name] = mixer.Sound( + SOUND_PATH + '{}.wav'.format(sound_name)) + self.sounds[sound_name].set_volume(0.2) + + self.musicNotes = [mixer.Sound(SOUND_PATH + '{}.wav'.format(i)) for i + in range(4)] + for sound in self.musicNotes: + sound.set_volume(0.5) + + self.noteIndex = 0 + + def play_main_music(self, currentTime): + if currentTime - self.noteTimer > self.enemies.moveTime: + self.note = self.musicNotes[self.noteIndex] + if self.noteIndex < 3: + self.noteIndex += 1 + else: + self.noteIndex = 0 + + self.note.play() + self.noteTimer += self.enemies.moveTime + + @staticmethod + def should_exit(evt): + # type: (pygame.event.EventType) -> bool + return evt.type == QUIT or (evt.type == KEYUP and evt.key == K_ESCAPE) + + def check_input(self): + self.keys = key.get_pressed() + for e in event.get(): + if self.should_exit(e): + sys.exit() + if e.type == KEYDOWN: + if e.key == K_SPACE: + if len(self.bullets) == 0 and self.shipAlive: + if self.score < 1000: + bullet = Bullet(self.player.rect.x + 23, + self.player.rect.y + 5, -1, + 15, 'laser', 'center') + self.bullets.add(bullet) + self.allSprites.add(self.bullets) + self.sounds['shoot'].play() + else: + leftbullet = Bullet(self.player.rect.x + 8, + self.player.rect.y + 5, -1, + 15, 'laser', 'left') + rightbullet = Bullet(self.player.rect.x + 38, + self.player.rect.y + 5, -1, + 15, 'laser', 'right') + self.bullets.add(leftbullet) + self.bullets.add(rightbullet) + self.allSprites.add(self.bullets) + self.sounds['shoot2'].play() + + def make_enemies(self): + enemies = EnemiesGroup(10, 5) + for row in range(5): + for column in range(10): + enemy = Enemy(row, column) + enemy.rect.x = 157 + (column * 50) + enemy.rect.y = self.enemyPosition + (row * 45) + enemies.add(enemy) + + self.enemies = enemies + + def make_enemies_shoot(self): + if (time.get_ticks() - self.timer) > 700 and self.enemies: + enemy = self.enemies.random_bottom() + self.enemyBullets.add( + Bullet(enemy.rect.x + 14, enemy.rect.y + 20, 1, 5, + 'enemylaser', 'center')) + self.allSprites.add(self.enemyBullets) + self.timer = time.get_ticks() + + def calculate_score(self, row): + scores = {0: 30, + 1: 20, + 2: 20, + 3: 10, + 4: 10, + 5: choice([50, 100, 150, 300]) + } + + score = scores[row] + self.score += score + return score + + def create_main_menu(self): + self.enemy1 = IMAGES['enemy3_1'] + self.enemy1 = transform.scale(self.enemy1, (40, 40)) + self.enemy2 = IMAGES['enemy2_2'] + self.enemy2 = transform.scale(self.enemy2, (40, 40)) + self.enemy3 = IMAGES['enemy1_2'] + self.enemy3 = transform.scale(self.enemy3, (40, 40)) + self.enemy4 = IMAGES['mystery'] + self.enemy4 = transform.scale(self.enemy4, (80, 40)) + self.screen.blit(self.enemy1, (318, 270)) + self.screen.blit(self.enemy2, (318, 320)) + self.screen.blit(self.enemy3, (318, 370)) + self.screen.blit(self.enemy4, (299, 420)) + + def check_collisions(self): + sprite.groupcollide(self.bullets, self.enemyBullets, True, True) + + for enemy in sprite.groupcollide(self.enemies, self.bullets, + True, True).keys(): + self.sounds['invaderkilled'].play() + self.calculate_score(enemy.row) + EnemyExplosion(enemy, self.explosionsGroup) + self.gameTimer = time.get_ticks() + + for mystery in sprite.groupcollide(self.mysteryGroup, self.bullets, + True, True).keys(): + mystery.mysteryEntered.stop() + self.sounds['mysterykilled'].play() + score = self.calculate_score(mystery.row) + MysteryExplosion(mystery, score, self.explosionsGroup) + newShip = Mystery() + self.allSprites.add(newShip) + self.mysteryGroup.add(newShip) + + for player in sprite.groupcollide(self.playerGroup, self.enemyBullets, + True, True).keys(): + if self.life3.alive(): + self.life3.kill() + elif self.life2.alive(): + self.life2.kill() + elif self.life1.alive(): + self.life1.kill() + else: + self.gameOver = True + self.startGame = False + self.sounds['shipexplosion'].play() + ShipExplosion(player, self.explosionsGroup) + self.makeNewShip = True + self.shipTimer = time.get_ticks() + self.shipAlive = False + + if self.enemies.bottom >= 540: + sprite.groupcollide(self.enemies, self.playerGroup, True, True) + if not self.player.alive() or self.enemies.bottom >= 600: + self.gameOver = True + self.startGame = False + + sprite.groupcollide(self.bullets, self.allBlockers, True, True) + sprite.groupcollide(self.enemyBullets, self.allBlockers, True, True) + if self.enemies.bottom >= BLOCKERS_POSITION: + sprite.groupcollide(self.enemies, self.allBlockers, False, True) + + def create_new_ship(self, createShip, currentTime): + if createShip and (currentTime - self.shipTimer > 900): + self.player = Ship() + self.allSprites.add(self.player) + self.playerGroup.add(self.player) + self.makeNewShip = False + self.shipAlive = True + + def create_game_over(self, currentTime): + self.screen.blit(self.background, (0, 0)) + passed = currentTime - self.timer + if passed < 750: + self.gameOverText.draw(self.screen) + elif 750 < passed < 1500: + self.screen.blit(self.background, (0, 0)) + elif 1500 < passed < 2250: + self.gameOverText.draw(self.screen) + elif 2250 < passed < 2750: + self.screen.blit(self.background, (0, 0)) + elif passed > 3000: + self.mainScreen = True + + for e in event.get(): + if self.should_exit(e): + sys.exit() + + def main(self): + while True: + if self.mainScreen: + self.screen.blit(self.background, (0, 0)) + self.titleText.draw(self.screen) + self.titleText2.draw(self.screen) + self.enemy1Text.draw(self.screen) + self.enemy2Text.draw(self.screen) + self.enemy3Text.draw(self.screen) + self.enemy4Text.draw(self.screen) + self.create_main_menu() + for e in event.get(): + if self.should_exit(e): + sys.exit() + if e.type == KEYUP: + # Only create blockers on a new game, not a new round + self.allBlockers = sprite.Group(self.make_blockers(0), + self.make_blockers(1), + self.make_blockers(2), + self.make_blockers(3)) + self.livesGroup.add(self.life1, self.life2, self.life3) + self.reset(0) + self.startGame = True + self.mainScreen = False + + elif self.startGame: + if not self.enemies and not self.explosionsGroup: + currentTime = time.get_ticks() + if currentTime - self.gameTimer < 3000: + self.screen.blit(self.background, (0, 0)) + self.scoreText2 = Text(FONT, 20, str(self.score), + GREEN, 85, 5) + self.scoreText.draw(self.screen) + self.scoreText2.draw(self.screen) + self.nextRoundText.draw(self.screen) + self.livesText.draw(self.screen) + self.livesGroup.update() + self.check_input() + if currentTime - self.gameTimer > 3000: + # Move enemies closer to bottom + self.enemyPosition += ENEMY_MOVE_DOWN + self.reset(self.score) + self.gameTimer += 3000 + else: + currentTime = time.get_ticks() + self.play_main_music(currentTime) + self.screen.blit(self.background, (0, 0)) + self.allBlockers.update(self.screen) + self.scoreText2 = Text(FONT, 20, str(self.score), GREEN, + 85, 5) + self.scoreText.draw(self.screen) + self.scoreText2.draw(self.screen) + self.livesText.draw(self.screen) + self.check_input() + self.enemies.update(currentTime) + self.allSprites.update(self.keys, currentTime) + self.explosionsGroup.update(currentTime) + self.check_collisions() + self.create_new_ship(self.makeNewShip, currentTime) + self.make_enemies_shoot() + + elif self.gameOver: + currentTime = time.get_ticks() + # Reset enemy starting position + self.enemyPosition = ENEMY_DEFAULT_POSITION + self.create_game_over(currentTime) + + display.update() + self.clock.tick(60) + + +if __name__ == '__main__': + game = SpaceInvaders() + game.main() From 731d705d498dea7e4b1ebaf542944fe8c7d385e8 Mon Sep 17 00:00:00 2001 From: ryas16308 <73746282+ryas16308@users.noreply.github.com> Date: Sat, 31 Oct 2020 19:45:46 +0530 Subject: [PATCH 22/35] Square.py --- Square.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Square.py diff --git a/Square.py b/Square.py new file mode 100644 index 00000000..dcb8251f --- /dev/null +++ b/Square.py @@ -0,0 +1,10 @@ +# Python Program to calculate the square root + +# Note: change this value for a different result +num = 8 + +# To take the input from the user +#num = float(input('Enter a number: ')) + +num_sqrt = num ** 0.5 +print('The square root of %0.3f is %0.3f'%(num ,num_sqrt)) From d36e814f7e97090fb4ed9bba9b1a10cde63a84be Mon Sep 17 00:00:00 2001 From: HIMANSHU JOSHI <30526784+himanshuJ007@users.noreply.github.com> Date: Sat, 31 Oct 2020 23:00:20 +0530 Subject: [PATCH 23/35] Create Hello World --- HelloWorld | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 HelloWorld diff --git a/HelloWorld b/HelloWorld new file mode 100644 index 00000000..0e3295e3 --- /dev/null +++ b/HelloWorld @@ -0,0 +1,3 @@ +# This program prints Hello, world! + +print('Hello, world!') From e937dcf304a85c417a53eb1e57e790bf37daf7da Mon Sep 17 00:00:00 2001 From: HIMANSHU JOSHI <30526784+himanshuJ007@users.noreply.github.com> Date: Sat, 31 Oct 2020 23:03:09 +0530 Subject: [PATCH 24/35] Create ReverseString --- ReverseString | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 ReverseString diff --git a/ReverseString b/ReverseString new file mode 100644 index 00000000..9a138931 --- /dev/null +++ b/ReverseString @@ -0,0 +1,14 @@ +# function which return reverse of a string + +def isPalindrome(s): + return s == s[::-1] + + +# Driver code +s = "malayalam" +ans = isPalindrome(s) + +if ans: + print("Yes") +else: + print("No") From 26d291257146bf959bd72dc47dad62f2127fc637 Mon Sep 17 00:00:00 2001 From: HIMANSHU JOSHI <30526784+himanshuJ007@users.noreply.github.com> Date: Sat, 31 Oct 2020 23:06:56 +0530 Subject: [PATCH 25/35] Create Add Two Numbers --- AddTwoNumber | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 AddTwoNumber diff --git a/AddTwoNumber b/AddTwoNumber new file mode 100644 index 00000000..01e1e135 --- /dev/null +++ b/AddTwoNumber @@ -0,0 +1,6 @@ +x = input("Type a number: ") +y = input("Type another number: ") + +sum = int(x) + int(y) + +print("The sum is: ", sum) From 2810efcfc1320f9d69762bb89dd29fbf964edb58 Mon Sep 17 00:00:00 2001 From: HIMANSHU JOSHI <30526784+himanshuJ007@users.noreply.github.com> Date: Sat, 31 Oct 2020 23:09:25 +0530 Subject: [PATCH 26/35] Create Multiply Two Numbers --- MultiplyTwoNUmbers | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 MultiplyTwoNUmbers diff --git a/MultiplyTwoNUmbers b/MultiplyTwoNUmbers new file mode 100644 index 00000000..e119a77c --- /dev/null +++ b/MultiplyTwoNUmbers @@ -0,0 +1,4 @@ +num_1 = 2 +num_2 = 3 +product = num_1 * num_2 +print("Product of {} and {} is {}".format(num_1, num_2,product)) From 039826a3ee06db94e496a8a0b78bc02f22114cb0 Mon Sep 17 00:00:00 2001 From: maheshwar2611 <44528734+maheshwar2611@users.noreply.github.com> Date: Sat, 31 Oct 2020 23:23:44 +0530 Subject: [PATCH 27/35] Create pg1.py --- pg1.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 pg1.py diff --git a/pg1.py b/pg1.py new file mode 100644 index 00000000..14f82dc8 --- /dev/null +++ b/pg1.py @@ -0,0 +1 @@ +print("Hello WOrld") From b52b316b0b18f0040055b73a0ce282de26ed7b03 Mon Sep 17 00:00:00 2001 From: maheshwar2611 <44528734+maheshwar2611@users.noreply.github.com> Date: Sat, 31 Oct 2020 23:24:16 +0530 Subject: [PATCH 28/35] Create pg2.py --- pg2.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 pg2.py diff --git a/pg2.py b/pg2.py new file mode 100644 index 00000000..14f82dc8 --- /dev/null +++ b/pg2.py @@ -0,0 +1 @@ +print("Hello WOrld") From 92997f115ef837a8aeab8e49dcdfff20180ef8c1 Mon Sep 17 00:00:00 2001 From: maheshwar2611 <44528734+maheshwar2611@users.noreply.github.com> Date: Sat, 31 Oct 2020 23:24:54 +0530 Subject: [PATCH 29/35] Create pg3.py --- pg3.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 pg3.py diff --git a/pg3.py b/pg3.py new file mode 100644 index 00000000..14f82dc8 --- /dev/null +++ b/pg3.py @@ -0,0 +1 @@ +print("Hello WOrld") From 26e94af235039a275de1ebe708255a4de8e3120f Mon Sep 17 00:00:00 2001 From: maheshwar2611 <44528734+maheshwar2611@users.noreply.github.com> Date: Sat, 31 Oct 2020 23:25:35 +0530 Subject: [PATCH 30/35] Create pg4.py --- pg4.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 pg4.py diff --git a/pg4.py b/pg4.py new file mode 100644 index 00000000..14f82dc8 --- /dev/null +++ b/pg4.py @@ -0,0 +1 @@ +print("Hello WOrld") From fd19265b84a98e09028e43200a00ec85f16b1533 Mon Sep 17 00:00:00 2001 From: writocraft <73071743+writocraft@users.noreply.github.com> Date: Sat, 31 Oct 2020 23:31:10 +0530 Subject: [PATCH 31/35] Create pg5.py --- pg5.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 pg5.py diff --git a/pg5.py b/pg5.py new file mode 100644 index 00000000..14f82dc8 --- /dev/null +++ b/pg5.py @@ -0,0 +1 @@ +print("Hello WOrld") From 422c29be52021411233349c67bb149d8c0fcd1a1 Mon Sep 17 00:00:00 2001 From: writocraft <73071743+writocraft@users.noreply.github.com> Date: Sat, 31 Oct 2020 23:31:41 +0530 Subject: [PATCH 32/35] Create pg5.py --- pg5.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 pg5.py diff --git a/pg5.py b/pg5.py new file mode 100644 index 00000000..14f82dc8 --- /dev/null +++ b/pg5.py @@ -0,0 +1 @@ +print("Hello WOrld") From 647904716df633822a4d3a02f211b3e7837cf285 Mon Sep 17 00:00:00 2001 From: writocraft <73071743+writocraft@users.noreply.github.com> Date: Sat, 31 Oct 2020 23:32:05 +0530 Subject: [PATCH 33/35] Create pg6.py --- pg6.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 pg6.py diff --git a/pg6.py b/pg6.py new file mode 100644 index 00000000..14f82dc8 --- /dev/null +++ b/pg6.py @@ -0,0 +1 @@ +print("Hello WOrld") From 30b1f797f822a07a5d190aed0888b64d57272a7c Mon Sep 17 00:00:00 2001 From: writocraft <73071743+writocraft@users.noreply.github.com> Date: Sat, 31 Oct 2020 23:32:11 +0530 Subject: [PATCH 34/35] Create pg7.py --- pg7.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 pg7.py diff --git a/pg7.py b/pg7.py new file mode 100644 index 00000000..14f82dc8 --- /dev/null +++ b/pg7.py @@ -0,0 +1 @@ +print("Hello WOrld") From 644baa05ac0d27879b04d8235bc58b995b3db882 Mon Sep 17 00:00:00 2001 From: writocraft <73071743+writocraft@users.noreply.github.com> Date: Sat, 31 Oct 2020 23:32:58 +0530 Subject: [PATCH 35/35] Create pg8.py --- pg8.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 pg8.py diff --git a/pg8.py b/pg8.py new file mode 100644 index 00000000..14f82dc8 --- /dev/null +++ b/pg8.py @@ -0,0 +1 @@ +print("Hello WOrld")