diff --git a/1operators.py b/1operators.py new file mode 100644 index 0000000..fd0e01c --- /dev/null +++ b/1operators.py @@ -0,0 +1,18 @@ +#boolean +a =10 +b=20 +print (a>b) +print (a=b) +print (a==b) +print (a!=b) +#logical +c1 = a>10 +c2 = b>10 +r1 = c1 and c2 +r2 = c1 or c2 +r3 = not(c1) +print(r1) +print(r2) +print(r3) \ No newline at end of file diff --git a/breakstatments.py b/breakstatments.py new file mode 100644 index 0000000..cb0c869 --- /dev/null +++ b/breakstatments.py @@ -0,0 +1,17 @@ +#1 +# i =1 +# while i<5: +# if i ==3: +# break +# print(i) +# i=i+1 +#2 +i=1 +while i<3: + j=1 + while j<5: + if j<3: + break + print(j) + j=j+1 + i=i+1 diff --git a/continue.py b/continue.py new file mode 100644 index 0000000..90915f9 --- /dev/null +++ b/continue.py @@ -0,0 +1,12 @@ +'''n = int(input()) +for i in range (2,n+1,2): + if i %7==0 : + continue + print(i)''' +#2 +n = int(input()) +for i in range(2,n+1,2): + print(i) + if i%7==0: + continue + print(i) \ No newline at end of file diff --git a/datatypes.py b/datatypes.py new file mode 100644 index 0000000..5ab03af --- /dev/null +++ b/datatypes.py @@ -0,0 +1,8 @@ +a = 10 +print(type(a)) +a = 'abcd' +print(type(a)) +a = True +print(type(a)) +a = 1303.99384748727979 +print(type(a)) \ No newline at end of file diff --git a/else.py b/else.py new file mode 100644 index 0000000..e69de29 diff --git a/else2.py b/else2.py new file mode 100644 index 0000000..7afcd63 --- /dev/null +++ b/else2.py @@ -0,0 +1,26 @@ +#2 +'''i=1 +while i <= 10 : + print(i) + i=i+1 +else : + print("this will print at end")''' + #2 by condition it has as print +i =1 +while i<5: + if i ==6: + break + print(i) + i=i+1 +else: + print("this will print at end") + #3 breaked by break so it else part will not print +i =1 +while i<5: + if i==3: + break + print(i) + i=i+1 +else : + print("this will print at end") + \ No newline at end of file diff --git a/flappybird.py b/flappybird.py new file mode 100644 index 0000000..38384b3 --- /dev/null +++ b/flappybird.py @@ -0,0 +1,215 @@ +import random # For generating random numbers +import sys #To exit the program +import pygame #pip install pygame +from pygame.locals import * +# Global Variables for the game +FPS = 32 +SCREENWIDTH = 289 +SCREENHEIGHT = 511 +SCREEN = pygame.display.set_mode((SCREENWIDTH, SCREENHEIGHT)) +GROUNDY = SCREENHEIGHT * 0.8 +GAME_SPRITES = {} +GAME_SOUNDS = {} +PLAYER = 'gallery/sprites/bird.png' +BACKGROUND = 'gallery/sprites/background.png' +PIPE = 'gallery/sprites/pipe.png' + +def welcomeScreen(): + + playerx = int(SCREENWIDTH/5) + playery = int((SCREENHEIGHT - GAME_SPRITES['player'].get_height())/2) + messagex = int((SCREENWIDTH - GAME_SPRITES['message'].get_width())/2) + messagey = int(SCREENHEIGHT*0.13) + basex = 0 + while True: + for event in pygame.event.get(): + # if user clicks on cross button, close the game + if event.type == QUIT or (event.type==KEYDOWN and event.key == K_ESCAPE): + pygame.quit() + sys.exit() + + # If the user presses space or up key, start the game for them + elif event.type==KEYDOWN and (event.key==K_SPACE or event.key == K_UP): + return + else: + SCREEN.blit(GAME_SPRITES['background'], (0, 0)) + SCREEN.blit(GAME_SPRITES['player'], (playerx, playery)) + SCREEN.blit(GAME_SPRITES['message'], (messagex,messagey )) + SCREEN.blit(GAME_SPRITES['base'], (basex, GROUNDY)) + pygame.display.update() + FPSCLOCK.tick(FPS) + +def mainGame(): + score = 0 + playerx = int(SCREENWIDTH/5) + playery = int(SCREENWIDTH/2) + basex = 0 + + # Create 2 pipes for blitting on the screen + newPipe1 = getRandomPipe() + newPipe2 = getRandomPipe() + + # List of upper pipes + upperPipes = [ + {'x': SCREENWIDTH+200, 'y':newPipe1[0]['y']}, + {'x': SCREENWIDTH+200+(SCREENWIDTH/2), 'y':newPipe2[0]['y']}, + ] + # List of lower pipes + lowerPipes = [ + {'x': SCREENWIDTH+200, 'y':newPipe1[1]['y']}, + {'x': SCREENWIDTH+200+(SCREENWIDTH/2), 'y':newPipe2[1]['y']}, + ] + + pipeVelX = -4 + + playerVelY = -9 + playerMaxVelY = 10 + playerMinVelY = -8 + playerAccY = 1 + + playerFlapAccv = -8 # velocity while flapping + playerFlapped = False # It is true only when the bird is flapping + + + while True: + for event in pygame.event.get(): + if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE): + pygame.quit() + sys.exit() + if event.type == KEYDOWN and (event.key == K_SPACE or event.key == K_UP): + if playery > 0: + playerVelY = playerFlapAccv + playerFlapped = True + GAME_SOUNDS['wing'].play() + + + crashTest = isCollide(playerx, playery, upperPipes, lowerPipes) # This function will return true if the player is crashed + if crashTest: + return + + #check for score + playerMidPos = playerx + GAME_SPRITES['player'].get_width()/2 + for pipe in upperPipes: + pipeMidPos = pipe['x'] + GAME_SPRITES['pipe'][0].get_width()/2 + if pipeMidPos<= playerMidPos < pipeMidPos +4: + score +=1 + print(f"Your score is {score}") + GAME_SOUNDS['point'].play() + + + if playerVelY GROUNDY - 25 or playery<0: + GAME_SOUNDS['hit'].play() + return True + + for pipe in upperPipes: + pipeHeight = GAME_SPRITES['pipe'][0].get_height() + if(playery < pipeHeight + pipe['y'] and abs(playerx - pipe['x']) < GAME_SPRITES['pipe'][0].get_width()): + GAME_SOUNDS['hit'].play() + return True + + for pipe in lowerPipes: + if (playery + GAME_SPRITES['player'].get_height() > pipe['y']) and abs(playerx - pipe['x']) < GAME_SPRITES['pipe'][0].get_width(): + GAME_SOUNDS['hit'].play() + return True + + return False + +def getRandomPipe(): + pipeHeight = GAME_SPRITES['pipe'][0].get_height() + offset = SCREENHEIGHT/3 + y2 = offset + random.randrange(0, int(SCREENHEIGHT - GAME_SPRITES['base'].get_height() - 1.2 *offset)) + pipeX = SCREENWIDTH + 10 + y1 = pipeHeight - y2 + offset + pipe = [ + {'x': pipeX, 'y': -y1}, #upper Pipe + {'x': pipeX, 'y': y2} #lower Pipe + ] + return pipe + + + + + + +if __name__ == "__main__": + # This will be the main point from where our game will start + pygame.init() # Initialize all pygame's modules + FPSCLOCK = pygame.time.Clock() + pygame.display.set_caption('Flappy Bird by CodeWithHarry') + GAME_SPRITES['numbers'] = ( + pygame.image.load('gallery/sprites/0.png').convert_alpha(), + pygame.image.load('gallery/sprites/1.png').convert_alpha(), + pygame.image.load('gallery/sprites/2.png').convert_alpha(), + pygame.image.load('gallery/sprites/3.png').convert_alpha(), + pygame.image.load('gallery/sprites/4.png').convert_alpha(), + pygame.image.load('gallery/sprites/5.png').convert_alpha(), + pygame.image.load('gallery/sprites/6.png').convert_alpha(), + pygame.image.load('gallery/sprites/7.png').convert_alpha(), + pygame.image.load('gallery/sprites/8.png').convert_alpha(), + pygame.image.load('gallery/sprites/9.png').convert_alpha(), + ) + + GAME_SPRITES['message'] =pygame.image.load('gallery/sprites/message.png').convert_alpha() + GAME_SPRITES['base'] =pygame.image.load('gallery/sprites/base.png').convert_alpha() + GAME_SPRITES['pipe'] =(pygame.transform.rotate(pygame.image.load( PIPE).convert_alpha(), 180), + pygame.image.load(PIPE).convert_alpha() + ) + + # Game sounds + GAME_SOUNDS['die'] = pygame.mixer.Sound('gallery/audio/die.wav') + GAME_SOUNDS['hit'] = pygame.mixer.Sound('gallery/audio/hit.wav') + GAME_SOUNDS['point'] = pygame.mixer.Sound('gallery/audio/point.wav') + GAME_SOUNDS['swoosh'] = pygame.mixer.Sound('gallery/audio/swoosh.wav') + GAME_SOUNDS['wing'] = pygame.mixer.Sound('gallery/audio/wing.wav') + + GAME_SPRITES['background'] = pygame.image.load(BACKGROUND).convert() + GAME_SPRITES['player'] = pygame.image.load(PLAYER).convert_alpha() + + while True: + welcomeScreen() + mainGame() \ No newline at end of file diff --git a/forloops.py b/forloops.py new file mode 100644 index 0000000..a097e61 --- /dev/null +++ b/forloops.py @@ -0,0 +1,10 @@ +'''s = 'abcd' +for c in s : + print (c) + #1 +n = int(input()) +for i in range(-9,n+1,1): + print(i)''' +#2 print n natural no +n = int(input()) +int diff --git a/forloops2.py b/forloops2.py new file mode 100644 index 0000000..dc97d7b --- /dev/null +++ b/forloops2.py @@ -0,0 +1,56 @@ +#1 +'''n = int(input()) +for i in range(0,n+1,1): + print(i) +#2 +n = int(input()) +for i in range(n+1): + print(i) +#3 +n = int(input()) +for i in range(1,n+1): + print(i) +#4 +n = int(input()) +for i in range(n,0,-1): + print(i)''' + #5 multiples of 3 +'''a = int(input()) +b = int(input()) +for i in range(a,b+1,1): + if(i%3==0): + print(i)''' +# or from above +'''a = int(input()) +b = int(input()) +if(a%3==0): + s = a +elif(a%3==1): + s=a+2 +elif(a%3==2): + s= a+1 +for i in range(s, b+1,3): + print(i)''' + #prime or no slow +n = int(input()) +flag = False +for d in range( 2, n, 1): + if n%d==0: + flag = True + +if flag : + print("not prime no") +else : + print('prime') +# prime or no very fast +n = int(input()) +flag = False +for d in range( 2, n, 1): + if n%d==0: + flag = True + break +if flag : + print("not prime no") +else : + print('prime') + diff --git a/functions1.py b/functions1.py new file mode 100644 index 0000000..85cbf4e --- /dev/null +++ b/functions1.py @@ -0,0 +1,17 @@ +def fact(a): + a_fact = 1 + for i in range(1, a+1) : + a_fact = a_fact * i + + + return a_fact + +n = int(input()) +r = int(input()) +n_fact= fact(n) +r_fact= fact(r) +n_rfact= fact(n-r) +ans = n_fact // (r_fact*n_rfact) +print(ans) + + diff --git a/functions2.py b/functions2.py new file mode 100644 index 0000000..095aedc --- /dev/null +++ b/functions2.py @@ -0,0 +1,9 @@ +n = int(input()) +d =2 +flag = False +if n/2==0 : + falg = True +if flag : + print('not prime') +else: + print('prime') \ No newline at end of file diff --git a/hello.py b/hello.py new file mode 100644 index 0000000..ae88c30 --- /dev/null +++ b/hello.py @@ -0,0 +1,4 @@ +print('hello world') +print("hello world") +n = int(input()) +print(n) diff --git a/ifelse.py b/ifelse.py new file mode 100644 index 0000000..8748ccb --- /dev/null +++ b/ifelse.py @@ -0,0 +1,34 @@ +# n = int(input()) +# is_even = (n%2==0) +# if is_even : +# print("n is even") +# else : +# print('n is odd') +# #or best example +# b = int(input()) +# if b%2==0 : +# print('n is even bro') +# else : +# print('nis odd bro') +# ELIF condition +# x = int(input()) +# y = int(input()) +# z = int(input()) +# if x>=y and x>=z : +# print('x is greater') +# elif y>=x and y>=z : +# print('y is greater') +# elif z>=x and z>=y : +# print('z is greater') +## nested statement +n = int(input()) +m = int(input()) +if n %2==0 : + print('n is even') + if m%2==0 : + print("m is even") + else : + print('m is odd') +else : + print('n is odd') + diff --git a/input.py b/input.py new file mode 100644 index 0000000..ae28c8b --- /dev/null +++ b/input.py @@ -0,0 +1,25 @@ +# # input deaflut at string +# a = input() +# print (a) +# print (type(a)) +# #incorrect example +# b = input() +# c = input() +# print(b+c) +# #correct example +# d = int(input()) +# e = int(input()) +# print(d +e) +# #another way +# f = '34' +# g = int(f) +# print(f) +#simple interst example +p = int(input('enter princpal ')) +r = int(input("ente rthe rate")) +t = int(input("enter the time")) +s = (p*r*t)/100 +z = (p-13)*5/9 +print(s) +print(z) + diff --git a/jarvis.py b/jarvis.py new file mode 100644 index 0000000..6f47f22 --- /dev/null +++ b/jarvis.py @@ -0,0 +1,113 @@ +# pip install pyaudio + +import pyttsx3 #pip install pyttsx3 +import speech_recognition as sr #pip install speechRecognition +import datetime +import wikipedia #pip install wikipedia +import webbrowser +import os +import smtplib + +engine = pyttsx3.init('sapi5') +voices = engine.getProperty('voices') +# print(voices[1].id) +engine.setProperty('voice', voices[0].id) + + +def speak(audio): + engine.say(audio) + engine.runAndWait() + + +def wishMe(): + hour = int(datetime.datetime.now().hour) + if hour>=0 and hour<12: + speak("Good Morning!") + + elif hour>=12 and hour<18: + speak("Good Afternoon!") + + else: + speak("Good Evening!") + + speak("I am Jarvis Sir. Please tell me how may I help you") + +def takeCommand(): + #It takes microphone input from the user and returns string output + + r = sr.Recognizer() + with sr.Microphone() as source: + print("Listening...") + r.pause_threshold = 1 + audio = r.listen(source) + + try: + print("Recognizing...") + query = r.recognize_google(audio, language='en-in') + print(f"User said: {query}\n") + + except Exception as e: + # print(e) + print("Say that again please...") + return "None" + return query + +def sendEmail(to, content): + server = smtplib.SMTP('smtp.gmail.com', 587) + server.ehlo() + server.starttls() + server.login('youremail@gmail.com', 'your-password') + server.sendmail('youremail@gmail.com', to, content) + server.close() + +if __name__ == "__main__": + wishMe() + while True: + # if 1: + query = takeCommand().lower() + + # Logic for executing tasks based on query + if 'wikipedia' in query: + speak('Searching Wikipedia...') + query = query.replace("wikipedia", "") + results = wikipedia.summary(query, sentences=2) + speak("According to Wikipedia") + print(results) + speak(results) + + elif 'open youtube' in query: + webbrowser.open("youtube.com") + + elif 'open google' in query: + webbrowser.open("google.com") + + elif 'open stackoverflow' in query: + webbrowser.open("stackoverflow.com") + + + elif 'play music' in query: + music_dir = 'D:\\Non Critical\\songs\\Favorite Songs2' + songs = os.listdir(music_dir) + print(songs) + os.startfile(os.path.join(music_dir, songs[0])) + + elif 'the time' in query: + strTime = datetime.datetime.now().strftime("%H:%M:%S") + speak(f"Sir, the time is {strTime}") + + elif 'open code' in query: + codePath = "C:\\Users\\Haris\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe" + os.startfile(codePath) + + elif 'email to harry' in query: + try: + speak("What should I say?") + content = takeCommand() + to = "harryyourEmail@gmail.com" + sendEmail(to, content) + speak("Email has been sent!") + except Exception as e: + print(e) + speak("Sorry my friend harry bhai. I am not able to send this email") + else: + print("No query matched") \ No newline at end of file diff --git a/number.py b/number.py new file mode 100644 index 0000000..442f4eb --- /dev/null +++ b/number.py @@ -0,0 +1,21 @@ +# 1 +a1 = 23 +a2 = 1 + 7j +print(a1) +print(a2) +print(type(a2)) +# 2 +a = 10 +print(id(a)) +a= a+1 +print(id(a)) +#3 +a =10 +b = 10 +print(id(a)) +print(id(b)) +#4 +a9 =1000 +b0 = 1000 +print(id(a9)) +print(id(b0)) \ No newline at end of file diff --git a/p1.py b/p1.py new file mode 100644 index 0000000..641e60b --- /dev/null +++ b/p1.py @@ -0,0 +1,21 @@ +a = int(input()) +b = int(input()) +if(a%3==0) : + for i in range(a,b+1,3): + print(i) +elif(a%4==0): + a= a+2 + if(a%3==0) : + for i in range(a,b+1,3): + print(i) +elif(a%5==0): + a= a+1 + if(a%3==0) : + for i in range(a,b+1,3): + print(i) +elif(a%2==0): + a= a+1 + if(a%3==0) : + for i in range(a,b+1,3): + print(i) + diff --git a/pass.py b/pass.py new file mode 100644 index 0000000..867c79c --- /dev/null +++ b/pass.py @@ -0,0 +1,5 @@ +i =3 +if i<7: + print + pass +print("hey") diff --git a/sum.py b/sum.py new file mode 100644 index 0000000..71fd54d --- /dev/null +++ b/sum.py @@ -0,0 +1,4 @@ +a =10 +b = 10 +sum = a+b +print(sum) \ No newline at end of file diff --git a/whileloops.py b/whileloops.py new file mode 100644 index 0000000..d3105b1 --- /dev/null +++ b/whileloops.py @@ -0,0 +1,33 @@ +# #first n natural no +# n = int(input()) +# count =1 +# while count<=n : +# print(count) +# count = count+1 +#print 1 for n times +# n = int(input()) +# count = 1 +# while count<=n: +# print(1) +# count += 1 +#print sum of even numbers +# n = int(input()) +# i = 0 +# sum = 0 +# while i<=n : +# sum += i +# i+=2 + +# print(sum) +# check prime no +n = int(input()) +d= 2 +flag = True +while d