Basics of Python programming

 Python programming

 

 Day -1 :

Fundamentals of python programming:

Data types : 

a) strings 

b) tuples 

c) lists 

d) dictionary 

e) numeric : Int , float, complex 

f ) sets 

g) boolean


Strings

1) concatenation

2) Modification

3) slicing

4) string methods


operators:

 

1) Arithmetic operators  : + , / ,* , / , // , % , **


2) Assignment operators : + = , - = , * =, / =, % = ,etc 


3) Comparison operators : = = , != , < , > .<= ,>=

4)Logical operators:AND , OR , NOT

5)Identity operators : is , is not

6)Membership operators : in , not in

7)Bit-wise operators : & , ~ , | , ^


Programs executed on day 1 (strings) :

1) Check if input by user is integer or not :

code :

               

a= input("Enter your data: ")
if(a.isnumeric()==True):
    print("the input is an integer")
else:
    print("input is not an integer")


2) Identifying unique words in a string :


code:

s=input("enter the string: ")
a=s.split()
print(a)
b= set(a)
print("the unique words are:",b)



3) Replacing spaces in a string by # key:

 code :


s=input("enter string: ")
print(s.replace(' ','#'))


4) Count of vowels appearing in user input string :

code:


st= input("enter str: ")
s=st.casefold()
p=0
q=0
r=0
z=0
t=0

b=len(s)
print(b)
for i in range(0,b):
     if s[i]=='a':
         p+=1

for i in range(0,b):
     if s[i]=='e':
         q+=1

for i in range(0,b):
     if s[i]=='i':
         r+=1

for i in range(0,b):
     if s[i]=='o':
         z+=1

for i in range(0,b):
     if s[i]=='u':
         t+=1

print("no of a's: ",p)
print("no of e's: ",q)
print("no of i's: ",r)
print("no of o's: ",z)
print("no of u's: ",t)



5) Printing largest and smallest word in string given by user :

code:


a=input("enter string : ")
a= a.split()
z=len(a[0])
x= 0

for i in a:
    j=len(i)
    if j>x:
        x=j

for i in a:
    j=len(i)
    if j==x:
        print("largest word is ", i)


for i in a:
    j = len(i)
    if j<z:
        z = j

for i in a:
    j = len(i)
    if j==z:
        w=i
print("smallest word is :",w)





Comments

Popular posts from this blog

Queue in Java

Using lists , tuples, sets, dictionaries

Blog on Pytest