0% found this document useful (0 votes)
16 views7 pages

COMPUTER

The document contains a series of Python programming exercises that cover various concepts such as finding the smallest number between two inputs, calculating areas of geometric shapes, checking for leap years, and determining the positivity of numbers. It also includes programs for calculating grades based on marks, summing numbers, printing even and odd numbers, and generating a Fibonacci series. Each program is presented with user input prompts and basic logic to achieve the desired outputs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views7 pages

COMPUTER

The document contains a series of Python programming exercises that cover various concepts such as finding the smallest number between two inputs, calculating areas of geometric shapes, checking for leap years, and determining the positivity of numbers. It also includes programs for calculating grades based on marks, summing numbers, printing even and odd numbers, and generating a Fibonacci series. Each program is presented with user input prompts and basic logic to achieve the desired outputs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

COMPUTER

PROGRAMS
1.Create a program in python to find the
smallest number b/w two numbers.
num1=int(input(‘Enter first number’))
num2=int(input(‘Enter second number’))
if(num1<num2):
print(‘smallest number is’,num1)
else:
print(‘smallest number is’,num2)

2.Create a program to calculate and print the


area of a rectangle if the user enters 1 and
print the area of a square if the user enters 2.
x=int(input(‘Enter choice 1 for area of a
rectangle’))
y=int(input(‘Enter choice 2 for area of a square’))
Ch=input(‘Enter a choice’)
print(‘choice entered is’, Ch)
if(Ch=1):
l=int(input(‘Enter length’))
b=int(input(‘Enter breadth’))
print(‘Area of rectangle is ‘, l*b)
elif (Ch==2):
s=int(input(‘Enter a side’))
print(‘Area of a square is’, s*s)
else:
print(‘Invalid choice’)

3.Create a program to check whether a year is


completely divisible by 4 or not. If it is, then
leap year otherwise not.
Year=int(input(‘Enter a year’))
If(year%4==0):
print(‘leap year’)
else:
print(‘Not a leap year’)

4.Using python’s script mode, print your


father’s name 5 times.
S1=str(input(‘Enter your father’s name’))
print(S1*5)

5.Create a program to check if a number input


by the user is positive or a negative number.
num=int(input(‘Enter a number”))
if(num>0):
print(‘Number is positive’)
else:
print(‘Number is negative’)

6.Write a program in python that accept marks


of five subjects entered by the user and
calculate percentage and grade on the basis
of following condition.
PERCENTAGE GRADE
>=90 A
>=80 B
>=70 C
>=60 D
>=40 E
<40 F
m1=int(input('Enter m1 marks'))
m2=int(input('Enter m2marks'))
m3=int(input('Enter m3 marks'))
m4=int(input('Enter m4 marks'))
m5=int(input('Enter m5 marks'))
total=m1+m2+m3+m4+m5
print('Total',total)
percentage=('total/500')*100
print('Percentage=',percentage),
if('percentage>90 and percentage<100'):
print('Grade A')
elif('percentage>80 and percentage<90'):
print('Grade B')
elif('percentage>70 and percentage<80'):
print('Grade C')
elif('percentage>60 and percentage<70'):
print('Grade D')
elif('percentage>40 and percentage<50'):
print('Grade E')
elif('percentage<40'):
print('Grade F')

7.To calculate the sum of n numbers using for


and while loop.
Using while loop
print("The sum is:",sum)
n=int(input("Enter a number"))
i=1
sum=0
while(i==n):
sum=sum+1
i=i+1
print+("Sum is=",sum)

Using for loop


n=int(input("Enter a number"))
sum=0
for i in range(i,n+1):
sum=sum+1

8.To print the sum of all the even numbers in


the range entered by the user.
n=int(input("Enter the range"))
sum=0
for i in range(n):
if i%2==0:
sum=sum=i
print("The sum of even
numbers=”,sum)

9.To print the negative odd numbers b/w 1 to


30.
Print(“odd numbers between -1 and -30 are”)
for i in range(-1, -31, -2):
print(i, end=” “)
10. To print the elements in the following
series 112358……
num=int(input("Enter the number of terms"))
x=1
y=1
print(x)
print(y)
for i in range(1,num+1):
z=x+y
print(z)
x=y
y=z

11. To print natural numbers from 0 to 9


using while loop.

n=int(input("Enter any number"))


i=1
print("The list of natural numbers are:")
while(i<=n):
print(i, end=" ")
i=1+1

You might also like