Posts

Showing posts from March, 2022

Game_01_Snake_Water_Gun_or_Rock_Paper_Scissor

  #snake water gun, or rock paper scissor import random def gameWin ( comp , you ):     if comp == you : # if two values are equal declear a tie         return None     #check for all possibilities when computer chose "s"     elif comp == 's' :         if you == 'w' :             return         elif you == 'g' :             return True     #check for all possibilities when computer chose "w"     elif comp == 'w' :         if you == 'g' :             return False         elif you == 's' :             return True     #check for all possibilities when computer chose "g"     elif comp == 'g' :         if you == 's' :           ...

use of list And tuple

# list  [  ]  l1 =[ 1 , 6 , 3 , 8 , 5 , 9 , 5 ] print ( l1 ) l1 . sort () print ( l1 ) print ( l1 [ 0 : 5 ]) # 0to 5 printed print ( l1 [ 0 : 7 : 2 ]) #alternat 1 place skiped #l1 = l1.replace("1","7") #this is use only for string not for list if you do so first change to string print ( l1 ) l1 . reverse () print ( l1 ) l1 . append ( 5 ) #add a new element at last in this list l1 . insert ( 5 , 100 ) # add an element at 6th place as 100 to existing list #l1.sort() print ( l1 ) l1 . pop ( 3 ) # it remove 3rd index value print ( l1 ) l1 . remove ( 8 ) #it remove element 8 from the list print ( l1 ) ################################ #creating a tuple using()(parenthesis) t =( 2 , 3 , 6 , 9 , 10 ) #printing the tuple print ( t [ 4 ]) #  it provide yo the 5th element of t n+1th element #you can't change or update the value of t #t[1]=90 # you will see an error you cant change the value of tuple #t1 =(2) #wrong way to assign a tuple use always a comma #t= (2,) # tupple...

String Function

  # String is a sequence of characters a = 34           # it is print as integer b = "sush"       # it is print as string print ( a , b )     # print ( a , type ( a ), b , type ( b )) # type cast #################################### string story = "once upon a time there was a student he know everything but he can't express the solution " #string function print ( len ( story ))   # len(story) , len use to count characters there is 9 character in thin two words print ( story . endswith ( "upto" )) # it says true or false what is at end of defined story print ( story . count ( "e" ))   # how many e are there in the sentence print ( story . capitalize ())   # its make first letter to Capital letter print ( story . find ( "time" ))   #'time' is start after 12 letter 13th character, it finds only first time if there is another time it cant find the second print ( story . replace ( "upon" , "there" )) ...

Python Codes practiced by me:- Creating a List, Tuple

 ################## ## Creating a list l1 =[ 1 , 6 , 3 , 8 , 5 , 9 , 5 ] print ( l1 ) l1 . sort () print ( l1 ) print ( l1 [ 0 : 5 ]) # 0to 5 printed print ( l1 [ 0 : 7 : 2 ]) # in 0 to7 alternate 1 place skipped #l1 = l1.replace("1","7") #this is use only for string not for list if you do so first change to string print ( l1 ) l1 . reverse () print ( l1 ) l1 . append ( 5 ) #add a new element at last in this list l1 . insert ( 5 , 100 ) # add an element at 6th place as 100 to existing list #l1.sort() print ( l1 ) l1 . pop ( 3 ) # it remove 3rd index value print ( l1 ) l1 . remove ( 8 ) #it remove element 8 from the list print ( l1 ) ################# #### #creating a tuple using()(parenthesis) t =( 2 , 3 , 6 , 9 , 10 ) #printing the tuple print ( t [ 4 ]) #  it provide yo the 5th element of t n+1th element #you can't change or update the value of t #t[1]=90 # you will see an error you cant change the value of tuple #t1 =(2) #wrong way to assign a tuple use alwa...

Modules, Comments and pip , Variable and Data Type, String and its Function

  Hello..... I am Sush_ _t During my learning python language I practice by making these small one to two line program to enhance my practice. play sound # import function # using pip from playsound import PlaySound PlaySound( 'C: \\ Sush \\ Python \\ Chapter1 \\ play.mp3' ) ############################### variable define x = "my name" h = '''asdfghj vbnygj bhjk kjbuyguyhb nmnmnbmn''' a = 'ssh' b = 465 c = 12.5   #printing the variable print ( a ) print ( b ) print ( h ) #printing the type of variable print ( type ( a )) print ( type ( c ))   Add two number or comments #add two numbers a = 5 b = 6 print ( a + b ) #average of two numbers and squre of the sME NUMBER a = input ( "enter first number :" ) #here a and b are string b = input ( "enter second number:" ) # a and b must be int so first we do type cast a = int ( a ) b = int ( b ) avg =(( a + b )/ 2 ) print ( "the avg of a and b is:" , a...