Python Certification Training for Data Scienc ...
- 51k Enrolled Learners
- Live Class
Technological advancements have lead to reduced effort. This makes Python programming language as one of the most sought out programming language due to its ease of access and readability. This also means a surge in the number of people experimenting with Python codes. In this blog, we will go through few of the most sought after fundamental python programs. Here is the list of same:
def pal(num): x1 = num[::-1] if x1 == x: print('palindrome') else: print('not a palindrome') print(pal('edureka'))
Factorial of a number is the product of all the positive numbers less than or equal to the number. The factorial of a number n is denoted by n!.
Following is the program to find the factorial of a number.
def fact(num): if num == 0: return num else: return num * fact(num - 1) print(fact(5))
Following is a program to print a fibonacci series.
a = int(input('enter the first element')) b = int(input('enter the second element')) n = int(input('enter the number of elements ')) print(a,b, end=" ") while n-2: c = a + b a = b b = c print(c, end=" ") n = n-1
It is a special number, If we sum the cube of each of the digits in an armstrong number it will be equal to the number itself.
Following is the python program to check whether a number is an armstrong number or not.
num = int(input('enter the nuber')) s = 0 temp = num while temp > 0: c = temp % 10 s += c**3 temp //= 10 if s == num: print('armstrong number') else: print('not an armstrong number')
Following is the program to create a calculator in python
def add(a,b): return a+b def sub(a,b): return a-b def prod(a,b): return a * b def div(a,b): return a / b def si(p, r, t): return (p*r*t) / 100 def ci(p, r ,t): return p * pow((1 + r/100), t) def sqr(num): return num**2 def sqrt(num) return num**0.5 print(add(10,15)) #to add two numbers, similarly you can use other functions for other operations.
Following is the program for patterns in python.
num = 5 a = (2 * num) - 2 for i in range(0, num): for j in range(0, a ): print(end=" ") for j in range(0, i+1) print('*' , end=" ") print(" ")
Following is the program to check if a year is a leap year
year = int(input('enter year')) if year % 400 == 0: print('it is a leap year') elif year % 4 == 0: print('it is a leap year') elif year % 100 == 0: print('not a leap year') else: print('not a leap year')
num = int(input('enter number')) for i range(2, num): if num% i == 0: print('not a prime number") break else: print('prime number') break
We will take the following shapes and try to calculate the area of all these shapes in python.
Following is the program to calculate areas in python
import math pi = math.pi def circle(radius): return pi * radius**2 def cube(side): return side**3 def cylinder(radius, height): return 2*pi*radius + 2*pi*height def sphere(radius): return 2*pi*(radius**2) print(circle(10)) #You can use other functions to calculate the areas of other shapes.
Following is the program to reverse a list
a = [1,2,3,4,5,6,7,8,9,10] print(a[: : -1]) #this will print the list in reverse.
have any questions? mention them in the comments, we will get back to you.