Posts

Showing posts from July, 2020

Healthy Programmer .Exercise.7

from pygame import mixer from datetime import datetime from time import time def mplay (file , stopper): mixer.init() mixer.music.load(file) mixer.music.play() while True : userinput = input () if userinput == stopper: mixer.music.stop() break def logactivity (msg): with open ( "Your Acvivity" , "a" ) as f: f.write( f" { msg } { datetime.now() } " ) if __name__ == '__main__' : water= 5 eyes= 10 phy= 15 init_water = time() init_eyes = time() init_exercise = time() while True : if time() - water > init_water: print ( "It is water drinking time.Enter=completed for stop the alarm" ) mplay( 'water.mp3' , 'completed' ) logactivity( " \n Water drink at:" ) if time() - eyes > init_eyes: print ( "It is eyes excrise time.Enter=completed for stop the alarm" ) mplay( 'eye.mp3' , 'comp

Modules😊

# #Random module example # import random # list=[1,3,5,7,9,11] # choice=random.choice(list) # print(choice) # #Image module example . Use ' when covering not " . Always use from Pil import image,BEC It is syntax # from PIL import Image # im = Image.open('C:\\Users\\alex9\\OneDrive\\Pictures\\images.jpg') # im.show() #time # import time # inpot=input() # if inpot=="what is time": # times=time.asctime() # print(times) # else: # print("You entered wrong word")

Snake Water Gun Game

import random options=[ "s" , "w" , "g" ] print ( "Welcome to snake water and gun game" ) humanpoints= 0 computerpoints= 0 chance= 10 noofchance= 0 print ( "Type \n s for snake \n w for water \n g for gun \n " ) while noofchance< 10 : userinput= input ( " \t\n Snake,Water,Gun:" ) computerinput=random.choice(options) #if tie if userinput == computerinput: print ( "#Tied by both .Because both choose same thing And no point given to anyone" ) print ( "#Your point is" , humanpoints) print ( "#Computer point is" , computerpoints) noofchance = noofchance + 1 else : print ( "" ) #if user enter s: if userinput== "s" and computerinput== "w" : print ( "Snake drank the water \n And 1 point added in side of human" ) humanpoints=humanpoints+ 1 print ( "#Your point is"

FUNCTIONS#3

#1EXAMPLE """" a=5 b=6 c=sum((a,b)) print(c) """ #2basic """"" def gd(a,b): print("Hi! Coder",a+b) gd(5,7) """ #3function and return """" def hd(a,g): average=(a+g)/2 #print(average) return average v=hd(3,5) print(v) """ #4 Doc string def hd (a,g): """Hi ! coders/programers or anyone if you see this after this date ,Hi it is 10-7-2020,15:31 PM""" average=(a+g)/ 2 print (average) return average print (hd. __doc__ )

FUNCTIONS#2

############ Functions and Docstrings Tutorial ################# # Function helps in code reuseability ########################################## ## Example of built in function a = 9 b = 8 # Sum is a inbuilt function in Python # takes tuple or list (more, general Iterables) as input c = sum (( a , b )) print ( c ) # Output : 17 ########################################## ## Example of user defined function ## The keyword def introduces a function definition. # It must be followed by the function name and # the parenthesized list of formal parameters. # The statements that form the body of the function # start at the next line, and must be indented. def function1 (): print ( "Hello you are in function 1" ) function1 () # Output : Hello you are in function 1 ##### Functions with Parameter & Return Statement #### # The 'return' statement returns with a value from a function. # 'return' without an expression argument returns None # if no

Loops

list1=[[ "Sus" , 10 ] , [ "Amongus" , 87 ] , [ "Potatus" , 10 ] , [ "Chungus" , 7 ] , [ "Meus" , 5 ]] for item , pop in list1: if type (pop)== int and pop> 6 : print (pop)