python examples كورس تعلم لغة بايثون من البداية , كورس تعلم بايثون كامل بالعربي , كورس تعلم بايثون من الصفر تعلم بايثون للمبتدى والمحترف ، دوره شاملة بايثون ، تمارين بايثون تعلم لغة بايثون .
Python3 program to add two numbers
Python3 program to add two numbers
Example
num1 = 15
num2 = 12
# Adding two nos
sum = num1 + num2
# printing values
print("Sum of {0} and {1} is {2}" .format(num1, num2, sum))
program to find simple interest for given principal amount, time and rate of interest.
program to find simple interest for given principal amount, time and rate of interest.
Example
# We can change values here for
# different inputs
P = int(input())
R = int(input())
T = int(input())
# Calculates simple interest
SI = (P * R * T) / 100
# Print the resultant value of SI
print("simple interest is", SI)
Find the factorial of given number
Find the factorial of given number
Example
def factorial(n):
if n < 0:
return 0
elif n == 0 or n == 1:
return 1
else:
fact = 1
while(n > 1):
fact *= n
n -= 1
return fact
num = 5;
print("Factorial of",num,"is",
factorial(num))
Program to find sum of square of first n natural numbers
Program to find sum of square of first n natural numbers
Example
def squaresum(n) : sm = 0 for i in range(1, n+1) : sm = sm + (i * i) return sm n = 4 print(squaresum(n))
Write a Python program to sum of all digits of a number
Write a Python program to sum of all digits of a number
Example
n=int(input("Enter a number:"))
sum=0
while n>0:
rem=n%10
sum=sum+rem
n=int(n/10)
print("The sum of digits of number is:", sum)
Write a program to check a year is a leap year or not using Python
Write a program to check a year is a leap year or not using Python
Example
year=int(input("Enter a Year:"))
if ((year % 100 == 0 and year % 400 == 0) or (year % 100 != 0 and year % 4 == 0)):
print("It is a Leap Year")
else:
print("It is not a Leap Year")
Write a program to convert Days into years, weeks and months using Python
Write a program to convert Days into years, weeks and months using Python
Example
days=int(input("Enter Day:"))
years =(int) (days / 365)
weeks =(int) (days / 7)
months =(int) (days / 30)
print("Days to Years:",years)
print("Days to Weeks:",weeks)
print("Days to Months:",months)
Python program to print all prime number in an interval
Python program to print all prime number in an interval
Example
start = 11 end = 25 for val in range(start, end + 1): # If num is divisible by any number # between 2 and val, it is not prime if val > 1: for n in range(2, val): if (val % n) == 0: break else: print(val)
Python program to find Area of a circle
Python program to find Area of a circle
Example
def findArea(r): PI = 3.142 return PI * (r*r); # Driver method print(findArea(5))
Python 3 code to find sum of elements in given array
Python 3 code to find sum of elements in given array
Example
def _sum(arr,n): # return sum using sum # inbuilt sum() function return(sum(arr)) # driver function arr=[] # input values to list arr = [12, 3, 4, 15] # calculating length of array n = len(arr) ans = _sum(arr,n) # display sum print (\'Sum of the array is \',ans)