Skip to main content

Posts

Featured Post

Python program to print Even numbers in between x and y

 Python program to print Even numbers in between x and y. Even numbers: The numbers which are  divisible by 2 or the numbers whose remainder is  0 are called even numbers. Input : enter x value 1 enter y value 7 Output :  even numbers between 1 and 7 are 2 4 6 Python program to display even numbers in range x , y #program to print even numbers in range x and y x=int(input("enter x ")) y=int(input("enter y ")) print(f"even numbers in between{x} and {y} are ") for i in range(x,y): if i%2==0: print(i) #use i,end=' ' to get output in single line Output : enter x 1 enter y 7 even numbers in between1 and 5 are 2 4 6
Recent posts

Python program to display odd numbers in range x , y

 Python program to print odd numbers in between x and y. Odd numbers: The numbers which are not divisible by 2 or the numbers whose remainder is  1 are called odd numbers. Input : enter x value  5 enter y value 10 Output :  odd numbers between 5 and 10 are 5 7 9  Python program to display odd numbers in range x , y #program to print odd numbers in range x and y x=int(input("enter x ")) y=int(input("enter y ")) print(f"odd numbers in between{x} and {y} are ") for i in range(x,y): if i%2!=0: print(i) #use i,end=' ' to get output in single line Output : enter x 5 enter y 10 odd numbers in between1 and 5 are 5 7 9

Python Program to find sum of n natural numbers

 Sum of n natural numbers Natural number : All positive integers are natural numbers. Input : enter n value 20 Output :  sum of 20 natural numbers is 210  Python Program to find sum of n natural numbers #program to find n natural numbers n=int(input("enter ")) nsum=0 if n >1: for i in range(1,n+1): nsum+=i print(f"sum of {n} natural numbers is {nsum}") else: print("enter a natural number") Output : enter 20 sum of 20 natural numbers is 210 Output : enter -3 enter a natural number

Program to find leap Year or not in Python

 What is a Leap year ? Generally  we have 28 days in the month of February and overall 365 days in a year. But a leap year have 29 days in the month of February and overall 366 days in a year. For every four years we get a leap year. Conditions to be a leap Year. Year divisible by 4 is a leap year until it is not divisible by 100 (century year{year ends with 00} is not a leap year until it is divisible by 400, if it is divisible by 400 then it is a leap year. Explanation :  For a non century year  if year divisible by 4 then it is a leap year. For a non century year  if year not divisible by 4 then it is not a leap year. If year is a century year then it is not a leap year. Century year is said to be a leap year if it is divisible by 400 . Input : enter a year 2400 Output :  2400 is a leap year  Program to find leap Year or not in Python #program to say leap year or not year=int(input("enter a year ")) if year%4==0: if year%100==0: if year...

Printing Multiplication table in Python

Display Multiplication table in Python Read an integer using input() function.   print(f"Multiplication table of {number} is") Use for loop to iterate multiplication for 10 times. print(number,"*",i,"=",number*i). As a result we get the output as a multiplication table of number. Input: enter any integer : 5 Output :  5 * 1 = 5 5 * 2 = 10 5 * 3 = 15 5 * 4 = 20 5 * 5 = 25 5 * 6 = 30 5 * 7 = 35 5 * 8 = 40 5 * 9 = 45 5 * 10 = 50 Program to display multiplication table in python.   #Multiplication table in python number=int(input("enter any integer ")) print(f"Multiplication table of {number} is") for i in range(1,11): print(f'{number}*{i}={number*i}') #---------without format specifiers---------# for i in range(1,11): print(number,"*",i,"=",number*i) Output : enter any integer 5 Multiplication table of 5 is 5 * 1 = 5 5 * 2 = 10 5 * 3 = 15 5 * 4 = 20 5 * 5 = 25 5 * 6 = 30 5 * 7 = 35 5 * 8 = 40 5 * 9 ...

Printing first n even and odd numbers in Python using for loop

for Loop in Python for  loop  -- Executes a sequence of statements multiple times and abbreviates the code that manages the    loop  variable. even and odd numbers An  even number  is a  number  that can be divisible by 2.   Even numbers  are  2, 4, 6, 8 and so on.  An  odd number  is a  number  that cannot be divisible by 2. Odd numbers  are 1, 3, 5, 7, 9 so on. Program to print first 10 even and odd numbers using for  loop. Input : how many even and odd nums you want 5 Output : first 5 even nums are  2 4 6 8 10  first 5 odd nums are  1 3 5 7 9 # Program to print first n even and odd numbers using for loop. choice = int(input("how many even and odd nums you want ")) n=(choice*2)+1 print("first",choice,"even nums are ") for i in range(1,n): if i%2 == 0: print(i,end=" ") print("\nfirst",choice,"odd nums are ") for i in range(1,n): if i%2!=0: print(...

volume of sphere and hemisphere in Python | program

 volume of sphere and hemisphere. Volume  of  hemisphere  = 2πr 3 /3, where 'r' is the radius of the  hemisphere . Volume  of  sphere  = 4πr 3 /3, where 'r' is the radius of the  sphere . Program to find volume of sphere and hemisphere Input : enter radius of sphere 4 enter radius of hemisphere 4 Output : volume of sphere is %.2f 268.08 volume of hemisphere is 134.04 # Program to find volume of sphere and hemisphere # for pi use pi value as 3.1423 or import math module from math import* #Program to find volume of sphere radius1 = float(input("enter radius of sphere ")) vol_sphere = (4*pi*radius1*radius1*radius1)/3 print("volume of sphere is %.2f",round(vol_sphere,2)) #Program to find volume of hemisphere radius2 = float(input("enter radius of hemisphere ")) vol_hemisphere = (2*pi*radius2*radius2*radius2)/3 print("volume of hemisphere is ",round(vol_hemisphere,2)) #here round(var,n) is predefined function used to get n digits afte...