0% found this document useful (0 votes)
3 views

python revision short programmes

The document provides a list of Python programming exercises for practice, covering various topics such as calculating areas, summing numbers, and working with loops. It includes sample programs demonstrating specific tasks like converting month names to days, counting even and odd numbers, and finding factors of a number. Each exercise is designed to help users improve their Python coding skills through practical implementation.

Uploaded by

punjwanizinnia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

python revision short programmes

The document provides a list of Python programming exercises for practice, covering various topics such as calculating areas, summing numbers, and working with loops. It includes sample programs demonstrating specific tasks like converting month names to days, counting even and odd numbers, and finding factors of a number. Each exercise is designed to help users improve their Python coding skills through practical implementation.

Uploaded by

punjwanizinnia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Here are some Python programs you might want to practice at home.

1. Write a Python program which accepts the radius of a circle from the user and
compute the area.
r = 1.1
Area = 3.8013271108436504

2. Write a Python program to get the difference between a given number and 17, if
the number is greater than 17 then print error message.

3. Write a Python program to sum of three given integers. However, if two values
are equal sum will be zero

4. Calculate the sum of all numbers from 1 to a given number

5. Display numbers from -10 to -1 using for loop

6. Use a loop to display elements from a given list present at odd index positions

7. Calculate the cube of all numbers from 1 to a given number

Sample Programs:
1. Write a Python program to convert a month name to number of
days. month_name = input("Input the name of Month: ")
if(month_name == "February"):
print("No. of days: 28/29 days")
elif (month_name=="April" or month_name=="June" or month_name=="September"
or month_name=="November"):
print("No. of days: 30 days")
elif (month_name=="January" or month_name=="March" or month_name=="May"
or month_name=="July" or month_name=="August" or month_name=="October"
or month_name=="December"):
print("No. of days: 31 day")

else:
print("Wrong month name")

2. Write a Python program to check whether an alphabet is a vowel or consonant


ch = input("Enter a character: ")
if(ch=='A' or ch=='a' or ch=='E' or ch =='e' or ch=='I' or ch=='i' or ch=='O' or ch=='o' or
ch=='U' or ch=='u'): print(ch, "is a Vowel")
else: print(ch, "is a Consonant")
3. Write a Python program that prints all the numbers from 0 to 10 except 2 and 8.
for x in range(11):
if (x == 2 or x==8):
continue
else: print(x)
4. Write a Python program to count the number of even and odd numbers
from a series of numbers provided by the user.

more="Y"

count_even=0
count_odd=0
while(more=="Y"):
x=int(input("Enter a number: "))
if not x % 2:
count_even=count_even+1
else:
count_odd=count_odd+1
more=input("Do you want to continue? Y/N ")
print("Number of even numbers :",count_even)
print("Number of odd numbers :",count_odd)
5. The program receives a number as input from user, and uses a while loop to
find the sum of digits of given number:

num=int(input("Enter a Number"))
sum = 0
while num>0:
remainder = num%10
sum = sum+remainder
num = int(num/10)
print("\nSum of Digits of Given Number: ", sum)

6. write a python program to count total digits available in a given number using
while loop.

num=int(input("Enter the Number: "))


tot = 0

while num:
num = int(num/10)
tot = tot+1

print("\nTotal Digit: ")


print(tot)

7. This program finds the sum of n numbers using for loop. Here the value
of n and then n numbers must be entered by user
sum = 0
n= int(input(“Enter the Value of n: "))
print("Enter " + str(n) + " Numbers: ")
for i in range(n):
num = int(input ()) # Using this block, we've received e.g 10 numbers and adds
the value and initialized to sum, one by one.
sum = sum+num
print("Sum of " + str(n) + " Numbers = " + str(sum))
using while loop
sum = 0
i=0
n=int(input("Enter the Value of n: "))
print("Enter " + str(n) + " Numbers: ")
while i<n:
num = int(input())
sum = sum+num
i = i+1
print("\nSum of " + str(n) + " Numbers = " + str(sum))

8. write a Python program to convert number of days into years, weeks and days.
num=int(input("Enter the Number of Days: "))
year = int(num/365)
week = int((num%365)/7)
days = int((num%365)%7)

print("Total Number of Year(s): ")


print(year)
print("Total Number of Week(s):")
print(week)
print("Total Number of Day(s):")
print(days)

9. write a Python program to find square root of a number

num=int(input("Enter a Number: "))


squareroot = num ** 0.5

print("\nSquare Root =", squareroot)

10. write a Python program to swap two numbers. Both the number must be
received by user.

a= int(input("Enter the First Number: "))


b= int(input("Enter the Second Number: "))

print("\nBefore Swap")
print("a =", a)
print("b =", b)

x=a
a=b
b=x

print("\nAfter Swap")
print("a =", a)
print("b =", b)
11. write a Python program to find factors of a number using while loop.

num=int(input("Enter the Number: "))

print("\nFactors of", num)

i=1
while i<=num:
if num%i==0:
print(i)
i = i+1

12. write a Python program to receive radius from user and print
circumference of circle.

print("Enter Radius of Circle: ")


r = float(input())
c = 3.14*r*r
print("\nCircumference = ", c)

13. Find Average of n Numbers using for Loop

To find average or arithmetic mean of n numbers entered by user in Python, you have
to ask from user to enter the value of n, and then n set of numbers, find and print the
average or arithmetic mean value of all those numbers as shown in the program given
below:

n=int(input(("Enter the Value of n: "))


print("Enter " +str(n)+ " Numbers: ")
num = [ ]
for i in range(n):
num.insert(i, int(input()))

# the statement, num.insert(i, int(input())) states that, the value entered by user gets
inserted at ith index of num

sum = 0
for i in range(n):
sum = sum+num[i]

avg = sum/n
print("\nAverage = ", avg)
14. # Area & Perimeter of Rectangle

length = float(input("Enter length of the rectangle: "))

breadth = float(input("Enter breadth of the rectangle: "))

area = length * breadth

perimeter = 2 * (length * breadth)

print("Area of rectangle = ", area)

print("Perimeter of rectangle = ", perimeter)

15. travelling record entry


travelling = input("Are you travelling? Yes or No:")
while travelling == 'yes':
num = int(input("Enter the number of people travelling:"))
for num in range(1,num+1):
name = input("Enter Details Name:")
age = input("Age:")
gender = input("Male or Female:")
print("Details Stored ",name)
print(age)
print(gender)
print("Thank you!")
travelling = input("Are you travelling? Yes or No:")
print("Please come back again.")

You might also like