P

@Puvi0707

Count string

Python
4 years ago
str = "he" message = "helloworldhellohello" print(message.count(str,0, len (message)))

Simple interest

Python
4 years ago
def simple_interest(p,t,r): print('The principal is', p) print('The time period is', t) print('The rate of interest is',r) si = (p * t * r)/100 print('The Simple Interest is', si) return si simple_interest(8, 6, 8)

Continue statement

Python
4 years ago
for i in range(1,11): if(i==5): continue print(i, end=" ") print("\n done")

Break statement

Python
4 years ago
i= 1 while i <=10: print(i, end=" ") if i==5: break i = i+1 print("\n done")

Sum of odd series

Python
4 years ago
n=int(input("Enter n value:")) sum=0 for i in range(1,n+1,2): sum+=i print(sum)

Multiplication pro using loop

Python
4 years ago
num= int(input(" Enter a number : ")) print("Table of: ") for a in range(1,11): print(num,'x',a,'=',num*a)

Factorial of no

Python
4 years ago
num=int(input("enter a number:")) factorial = 1 if num < 0: print("Sorry, factorial does not exist for negative numbers") elif num == 0: print("The factorial of 0 is 1") else: for i in range(1,num + 1): factorial = factorial*i pri

String operation slice of str

Python
4 years ago
str='python is easy' print(str) print(str[0]) print(str[3:9]) print(str[4:]) print(str[-1]) print(str[:5]) print(str*2) print(str+"isn't it?")

String operation concat,multi,

Python
4 years ago
a=('12+'34') print(a) str='hello' print(str+'4') print(str*5)

Logical operators

Python
4 years ago
a=int(input("Enter a number:")) b=int(input("Enter a number:")) print("A=",a,"and B = ",b)) print("The a>b or a==b=",a>b or a==b) print("The a >b or a == b=",a>b and a == b print ( "The not a>b = ", not a>b)

Arithmetic operators

Python
4 years ago
print('Arithmetic operators') x=int(input("Enter a value:")) y=int(input ("Enter a value:")) print('Addition:',x+y) print('subtraction:',x-y) print('multiplication:',x*y) print('divison:',x*y) print('modulous:',x%y) print('Exponentiation:',x**y) pri

Find the substring with argu using func

Python
4 years ago
def sub_str(str1,str2): if str1 in str2: print("the substr is found") else: print("the substr is not found") sub_str('alia' ,'batt')

Largest of 3 nos using func with argu

Python
4 years ago
def maximum (a,b,c): if(a>b) and (a>c): print(a,'is the largest number') elif(b>a and b>c): print(b,"is the largest number") else: print(c,'is the largest number') maximum (25,13,20) maximum (17,18,16) maximum (39

Leap year using func with argu

Python
4 years ago
def leap_year(): if(year%4==0): if(year%100==0): if(year%400==0): print('leap year') else: print(' not a leap year') else: print(' leap year') else:

Pos,neg,or 0 using func without argu pr1

Python
4 years ago
def integer_type(): if(n==0): print(n,'is zero') elif(n>0): print(n,'is a positive integer') elif(n<0): print(n,'is a negative integer') n=int(input('enter any integer:')) integer_type()

File for write

Python
4 years ago
fruits = [“Apple\n”, “Orange\n”, “Grapes\n”, “Watermelon”] my_file = open(“C:/Documents/Python/test.txt”, “w”) my_file.writelines(fruits)

File for read

Python
4 years ago
my_file = open(“C:/Documents/Python/test.txt”, “r”) print(my_file.read(5))

Sort

Python
4 years ago
t1=(3,8,6,7,4,2,5) print(sorted(t1)) l1=[3,6,7,8,5,7,9] print(l1.sort()) print(l1.sort(reverse='true'))

Enumerate

Python
4 years ago
for index,element in enumerate ('ABCDEFG') print(index,element)

List & tup 3

Python
4 years ago
t=((1,'a'),(2,'b'),(3,'c')) for i,char in t: print(i,char)