1. Write a program to accepts two integers and print their sum.
# Write a program to accepts two integers and print their sum.
a=int(input('Enter the first integer:'))
b=int(input('Enter the second integer:'))
Sum=a+b
print('The two integers are:', a, b)
print('The sum of two integers are:', Sum)
2. Write a program that accepts the radius of a circle and prints its area
# 2. Write a program that accepts radius of a circle and prints its area.
r=int(input('Enter the radius of circle:'))
Area=3.14*r**2
print('The area of the circle is:', Area)
3. Write a program that accepts base and height and calculate the area of a triangle.
#Write a program that accepts base and height and calculate the area of triangle
b=float(input('Enter the base of triangle:'))
h=float(input('Enter the height of triangle:'))
Area=(1/2)*b*h
print('The area of triangle is:', Area)
4. Write a program to calculate simple interest.
# Write a program to calculate simple interest.
P=float(input('Enter the principal amount in : '))
R=float(input('Enter the rate of interest: '))
T=float(input('Enter the time in years: '))
SI=(P*R*T)/100
print('The simple interest is : ', SI)
5. Write a program to find whether a given number is even or odd.
# Write a program to find whether a given number is even or odd.
a=int(input('Enter the number:'))
if a%2==0:
print('The number is even')
else:
print('The number is odd')
6. Write a program to find the largest among the three integers.
# Write a program to find largest among three integers
a=int(input('Enter the first integer:'))
b=int(input('Enter the second integer:'))
c=int(input('Enter the third integer:'))
if a>b and a>c:
print(a, 'is the largest integer')
if b>a and b>c:
print(b, 'is the largest integer')
if c>a and c>b:
print(c, 'is the largest integer')
7. Write a program that accepts the age and print if one is eligible to vote or not.
# Write a program that accepts the age and
# print if one is eligible to vote or not.
a=int(input('Enter your age:'))
if a>=18:
print('You are eligible to vote')
else:
print('You are not eligible to vote')
8. Write a program to accept the year and check if it is a leap year or not.
# Write a program to accept the year and
# check if it is a leap year or not.
a=int(input('Enter the year:'))
if a%4==0:
print('This year is a leap year')
else:
print('This year is not a leap year')
9. Write a program to input percentage marks of a student and find the grade as per the following
criterion:
'''
Write a program to input percentage marks of a student and find the grade as per following
criterion:
Marks Grade
>=90 A
75-90 B
60-75 C
Below 60 D
'''
a=float(input('Enter the percentage marks:'))
if a>=90:
print('The student has got an A grade')
elif a>=75 and a<90:
print('The student has got a B grade')
elif a>=60 and a<75:
print('The student has got a C grade')
else:
print('The student has got a D grade')
10. Write a program to enter a number and check if it is a prime number or not.
# Write a program to enter a number and
# check if it is a prime number or not.
num=int(input('Enter the number:'))
for i in range(2,num//2+1):
if num%i==0:
print('It is not a prime no.')
break
else:
print('It is a prime number')
11. Write a program to print the sum of natural numbers between 1 to 7. Print the sum
progressively i.e. after adding each natural number, a print sum so far.
# Write a program to print the sum of natural numbers between 1 to 20.
# Print the sum progressively i.e. after adding each natural number,
# print sum so far.
Sum=0
for n in range(1,21):
Sum+=n
print('Sum of natural numbers <=',n,'is',Sum)
12. Write a program to calculate the factorial of a number.
# Write a program to calculate the factorial of a number.
num=int(input('Enter a number:'))
fact=1
a=1
while a<=num:
fact*=a
a+=1
print('The factorial of',num,'is',fact)
13. Write a program to create a triangle of stars using a nested loop.
# Write a program to create a triangle of stars using nested loop.
for i in range(1,6):
print()
for j in range(1,i):
print('*',end=' ')
14. Write a program to print a pattern like:
4321
432
43
'''
Write a program to print a pattern like:
4321
432
43
4
'''
for i in range(4):
for j in range(4,i,-1):
print(j,end=' ')
else:
print()
15. A program that reads a line and prints its statistics like:
The number of uppercase letters:
The number of lowercase letters:
The number of alphabets:
The number of digits:
#Program that reads a line and print its statistics like:
'''
Number of uppercase letters:
Number of lowercase letters:
Number of alphabets:
Number of digits:
'''
line=input('Enter a line:')
lowercount=uppercount=0
digitcount=alphacount=0
for a in line:
if [Link]():
lowercount+=1
elif [Link]():
uppercount+=1
elif [Link]():
digitcount+=1
if [Link]():
alphacount+=1
print('Number of uppercase letters are:',uppercount)
print('Number of lowercase letters are:',lowercount)
print('Number of alphabets are:',alphacount)
print('Number of digits are:',digitcount)