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:", avg, type(avg))

print ("squre of a: and b :", a*a,   b*b)


#this is a input function program




a=input ("Enter your name ") # what would be entered it read as string type

a=int(a)  # convert a to an integer (if possible)

print(type(a)) # if it is possible it read the typecast ie type of input


# remainder when we divide a number


a=45
b=8

print ("the remainder when a is divided by b is" ,( a%b))
# % command gives remainder

############################
#Printing variable and its type

x="my name"
h='''as you see this you try
and try then you learn this language
bhjk
kjbuyguyhb
nmnmnbmn SushantSashu''' # triple Quote is use for multi line comment
            # (#) is use for single line comment

a = 'ssh' # string
b = 465 # integer
c = 12.5 # float
 #printing the variable
print(a)
print(b)
print(h)
#printing the type of variable
print(type(a))
print(type(c))  

# 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)) # by default it print as string

# string slicing


greeting = "Good Morning"
name = "sushantsahu"
#print (type(name))

#print (greeting + name)  #both string added in single line is new string

# Concatenating two strings
#b = (greeting + name)
#print(b)

#print (greeting [7]) # it print 7th character of string start from zero ie 'r'
#'''  we cant change the item of string by
#name[3]="p" ,
#ie change 3rd character as 'p'''  # tripple quote is comment'''
 
print (name[0:3])
print(greeting[1:7])
print (name[:3])     # is same as name [0:3]
print (name[0:])     # is same as name [0:up tu last character of string]
print (name[0:9:2])  # 1to 9 every 2nd character is skiped


# String Function Date 26/06/2019

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(sory) , len use to count characters there is 9 character in thin two words
print(story.endswith("upo")) # it says true or false what is at end of defined story
print (story.count("e"))  # how many e are there in the santence
print (story.capitalize())  # its make first letter to CAlital 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"))  #this can replaCE upon to there , all reoccuring words , all upon to there.

##################
# Scape sequence Character

story = "he is good. \nhe is verry good. " # \n enter to new line while printing
print (story)  # \n- new line \t- tab, \' - quote, \\ - backslash

###################

@ # write a py program to display a user enter name followed by GoodAfternoon using input fn.
# Eg Good Afternoon Sush. ie string addition

# Name = input() # ("Enter your name ")
#Name = input("enter your Name")
Name = input("enter your Name\n")

#print("good afternoon, " + Name) # if you want to see it in a new line use \n new line command

print("good afternoon,\n " + Name)

#######################
# Letter templet for an office

letter = '''
        Dear <|Name|>,
Greetings from PVM School,
Happy to inform you that
        Your are selected! for the post of \n Assistanc teacher.

        Have a Great day.

        Date: <|DATE|>
 
'''
name = input("enter Your Name\n")
date = input ("enter Date \n")
letter = letter.replace("<|Name|>", name)
letter = letter.replace("<|DATE|>", date)

print (letter)


#######################################

# it is to find any character or data in any string.
# to find duble space we use Find string function in a string

st = "this is a string with  double spaces sentence" # -1 is no space, if any number ie at thate place there is a DS

doublespaces = (st.find("  "))  # double space , more than one DS it dont find second  
print (doublespaces)

st= st.replace("  "," ") # if there is any DS replace with SS single space and print it

print(st)

st= st.replace("sentence","word ") #it is a replace function
print(st)

note:-- Always use typecast when you play with numbers.

#################### Use of scape Sequence Character

scape sequence CHARACTERS
#letter= "dear Sush,This is my new program to verify escape sequence character. thank you"

letter= "dear Sush,\n This is my new program\n\t to \t \n \t verify \n \t\" escape sequence character\" \n \t thank you! \n)"


print(letter)


############### I update second list of my practice during learning process of Python

a= "thank you"
print(a)



Comments

Popular posts from this blog

Game_01_Snake_Water_Gun_or_Rock_Paper_Scissor

String Function

Conditional Expression