P

@Puvi0707

Gn no is prime or composite

Python
4 years ago
number = int(input('enter number:')) iscomposite = 0 for i in range(2,number): if(number%i ==0): isconposite = 1 break if(iscomposite == 1): print("number is composite") else: print("number is prime")

Slice operation with stride

Python
4 years ago
str = "welcome to the world of python" print("str[2:10] = ", str[2:10]) print("str[2:10:1] = ", str[2:10:1]) print("str[2:10:2] = ", str[2:10:2]) print("str[2:13:4] = ", str[2:13:4])

Zip()

Python
4 years ago
tup = (1,2,3,4,5) list1 = ['a','b','c','d','e'] print(list((zip(tup,list1))))

Reduce ()

Python
4 years ago
import functools def add(x,y): return x+y num_list = [1,2,3,4,5] print("sum of values in list = ") print(functools.reduce(add,num_list))

Map()

Python
4 years ago
def add_2(x): x += 2 return x num_list = [1,2,3,4,5,6,7] print("original list is :",num_list) new_list = list(map(add_2,num_list)) print("modified list is:",new_list)

Filter() list of nos div by 2,4 using list comprehensive

Python
4 years ago
def check(x): if (x%2 == 0 or x%4 == 0): return 1 evens = list(filter(check,range(2, 22))) print(evens)

Filter function

Python
4 years ago
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] # returns True if number is even def check_even(number): if number % 2 == 0: return True return False # Extract elements from the numbers list for which check_even() returns True

List operation using for loop

Python
4 years ago
thislist = ["apple", "banana", "cherry"] for i in range(len(thislist)): print(thislist[i])

Armstrong no

Python
4 years ago
n = int(input("enter the number:")) s = 0 num = n while(n!=0): r = n%10 s = s+(r*r*r) n = int(n/10) if(s==num): print("the number is Armstrong") else:

Logical operators not

Python
4 years ago
a = 10 b = not a print(int(b))

Logical operators or

Python
4 years ago
a = 10 b = 12 c = 0 if (a>b) or (b>c): print("All the numbers have boolean value as True") else: print("Atleast one number has boolean value as False")

Logical operators and

Python
4 years ago
a = 10 b = 12 c = 0 if a and b and c: print("All the numbers have boolean value as True") else: print("Atleast one number has boolean value as False")

Divisible by 5 using for loop

Python
4 years ago
def NumGen(n): for j in range(1, n+1): if j % 5 == 0: yield j if __name__ == "__main__": N = 10 for j in NumGen(N): print(j, end = " ")

Reverse of a number

Python
4 years ago
num = int(input("enter the number: ")) print("the reversed number is :",) while(num!=0): temp = num%10 print(temp, end=" ") num = int(num/10)

Sum of its digit

Python
4 years ago
sumofdigits = 0 num =int(input("enter the number:")) while(num!=0): temp=num%10 sumofdigits = sumofdigits + temp num=num/10 print("the sum of digits is :",sumofdigits)

Sum and avg

Python
4 years ago
i = 0 s = 0 while(i<=10): s = s+i i=i+1 avg = float(s)/10 print("the sum of first 10 numbers is :",s) print("the average of first 10 numbers is :", avg

Sum of even nos using while loop

Python
4 years ago
maximum = int(input(" Please Enter the Maximum Value : ")) total = 0 number = 1 while number <= maximum: if(number % 2 == 0): print("{0}".format(number)) total = total + number number = number + 1

Relational or comparison operators

Python
4 years ago
a=100 b=200 print(a==b) print(a!=b) print(a>b) print(a<b) print(a>=b) print(a<=b)

Fibonacci recursion

Python
4 years ago
def fibonacci(n): if(n<2): return 1 return(fibonacci(n-1)+fibonacci(n-2)) n=int(input('enter the number of terms:')) for i in range(n): print("fibonacci(",i,")=",fibonacci(i))

String without vowel

Python
4 years ago
import re def rem_vowel(string): return(re.sub("[aeiouAEIOU]","",string)) string = "GeeksforGeeks - A Computer Science Portal for Geeks" print(rem_vowel(string))