1. Write a program to display your name and age.
a = (input("Enter your name: "))
b = int(input("Enter your age: "))
print("Your name is", a)print("Your age is", b)
2. Write a program to find the area of a square using the length of the side entered by the user.
side = int(input('Enter the side: '))
area = side * side
print('Area of a square is: ', area)
3. Write a program to find the area and perimeter of a rectangle using the length and breadth entered by the user.
width = float(input('Please enter width of a Rectangle:
'))
height = float(input('Please enter height of a Rectangle:'))
area = width * height
perimeter = 2 * (width + height)
print('\n Area of a Rectangle is :%.2f' %area)
print('\n Perimeter of a Rectangle is :%.2f' %perimeter)
4. Write a program to find out the area of the Triangle using the base and height entered by the user.
base = float(input("Enter base of a triangle"))
height = float(input("Enter height of a triangle"))
area = 0.5 * base * height
print("Area of a triangle is: ", area)
5. Write a program to find out the Perimeter of Triangle using the length of the sides entered by the user.
a = float(input('Enter the length of the first side in cm :
'))
b = float(input('Enter the length of the second side in cm :
'))
c = float(input('Enter the length of the third side in cm :
'))
perimeter = a + b + c
print('The perimeter of the triangle is', perimeter)
6. Program to allow user to enter 3 subject marks and find out total and average.
Math = int(input('Enter Math marks: '))
ICT = int(input('Enter ICT marks: '))
English = int(input('Enter English marks: '))
total = int(Math + ICT + English)
print('Your total marks are: ',total)
avg = (int(total/3))
print('Your Average is: ',avg)
7. Program to add two words "Good" and "Morning" using string operations. And display the word "happy" 5 times.
str1= 'Good'
str2= ' Morning'
str3='Happy'
print('str1 + str2=',str1 + str2)
print('str3 * 5= ',str3 * 5)
8. Write a program to check whether number entered by user is a positive number or not using if statement.
num=int(input('Enter a number: '))
if num > 0:
print("Positive
number")
else:
print("Negative
number")
9. Using the if...else statement, write a program to accept
a number from the user and check whether
that number is odd or an even number.
#program
to check whether a number is odd or even number. num=int(input('Enter a number: ')) #taking
input from user
mod=num%2 #remainder gets stored in mod variable
if mod>0:
print('This is an odd number.')
else:
print('This is an even number.')
10. Write a program using if...else statement to find the
largest of two user input numbers.
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
if b > a:
print("b is
greater than a")
else:
print("a is
greater than b")
11. Write a program to check whether a student has passed or
failed based on his marks out of 150.
(passing marks - 60 and above).
#program to find whether a student has passed or
failed.
marks=int(input('Enter the marks out
of 150: ')) #taking input from user if
marks>=60:
print('passed')
else:
print('failed')
12. Write a program to print the numbers 0 to 9 using for
loop. #program to print the
0 to 9 numbers using for loop.
i=0 #assign 0 as start value to variable i
for item in range(0,10): #specified range for 10
numbers
print(i)
i=i+1 #after each loop variable i is increased by 1
13. Write a program to print the multiplication tables of
any number using for loop.
#program to print the table of any number using for loop
n=
int(input('Enter the number: ')) #n will store the user input value for t in range(1,11):
print(n, 'x',t,'=',n*t)
14. Write a program to display the list [red, blue, yellow,
green] using a for loop.
# program
to display the list [red, blue, yellow, green] using for loop. color=['red','blue','yellow','green']
for i in color:
print(i)
15. Write a program to print numbers in descending order starting from 5.
i=5
while i!=0: #checks if value in variable i is not equal to
0
print(i)
i=i-1 #value in variable i gets decreased by 1
16. Write a program to print the first 5 even numbers using a while loop.
n=1 #n acts as counter
num=0 #num will store the even values and print it
while n<=5:
print(num)
n=n+1
num=num+2
No comments:
Post a Comment