0% found this document useful (0 votes)
7 views3 pages

Python Programs Midterm

The document contains a series of Python programs that demonstrate basic programming concepts. These include calculating the area of a rectangle, checking if a number is even or odd, determining if a number is positive, negative, or zero, and finding the greatest of two numbers. Additional programs cover printing sequences, Fibonacci series, even numbers, multiplication tables, and calculating factorials.
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)
7 views3 pages

Python Programs Midterm

The document contains a series of Python programs that demonstrate basic programming concepts. These include calculating the area of a rectangle, checking if a number is even or odd, determining if a number is positive, negative, or zero, and finding the greatest of two numbers. Additional programs cover printing sequences, Fibonacci series, even numbers, multiplication tables, and calculating factorials.
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

1. Write a Python program to find the area of a rectangle.

L=int(input("Enter Length"))
B=int(input("Enter Bredth"))
c=L*B
print("Area of rectangle",c)

2. Write a Python program to check whether a number entered by user is even or odd.
number = float(input("Enter a number: "))

if number % 2 == 0:
print("The number is even.")
else:
print("The number is odd.")

3. Write a Python program to check whether a number entered by user is positive, negative or zero.
num = float(input("Enter a number: "))

# Check if the number is positive, negative, or zero


if num > 0:
print("The number is positive.")
elif num < 0:
print("The number is negative.")
else:
print("The number is zero.")

4. Write a Python program to check the year entered by user is a leap year or not.
Year = int(input("Enter the number here: "))
if((Year % 400 == 0) or (Year % 100 != 0) and (Year % 4 == 0)):
print("Yes! This Year is a leap Year");

else:
print ("This Year is not a leap Year")

5. Write a Python program to accept two numbers from the user and find the greatest number.
A=int(input("Enter A value:"))
B=int(input("Enter B value:"))
if A>B:
print("A is Bigger")
else:
print("B is Bigger")

6. Write a Python program to print the values in a given sequence of numbers (10, 20, 30, 40, 50)
for i in range(10,60,10):
print(i)

7. Write a Python program to print the numbers from 0 to 9 using for loop.
for i in range(10):
print(i)
8. Write a Python program to print the squares of the numbers from 1 to 10 using for loop.
i=1
for i in range(10):
print(i**2)

9. Write a Python program to print a Fibonacci series upto 8th term.


n=8
num1 = 0
num2 = 1
next_number = num2
count = 1

while count <= n:


print(next_number, end=" ")
count += 1
num1, num2 = num2, next_number
next_number = (num1+num2)
print()

10. Write a Python program to print the even numbers between 1and 30 using for loop.
print("Even number from 1 to 30 are:")
for i in range(1,30):
if i%2==0:
print(i)

11. Write a Python program to print the multiplication table of a number entered by the user using while
loop.
n=int(input("Enter a number:"))
for i in range(1, 11):
print(n, 'x', i, '=', n*i)

12. Write a Python program to print first 10 natural numbers using while loop.
i=1
while i<=10:
print(i)
i+=1

13. Write a Python program to print the sum of first 10 natural numbers using while loop.
N = 10
sum = 0

# Calculate the sum using a for loop


for i in range(1, N + 1):
sum += i
print(sum)

14. Write a Python program to accept two numbers from the user and perform addition, subtraction,
multiplication and floor division with the two numbers and display the results.

a=80
b=50
print("Addition of two numbers is",a+b)
print("Substraction of two numbers is",a-b)
print("Multiplication of two numbers is",a*b)
print("Floor division of two numbers is",a//b)

15. Write a Python program to find the factorial of a number entered by user
n = int (input ("Enter a number: "))
factorial = 1
if n >= 1:
for i in range (1, n+1):
factorial=factorial *i
print("Factorial of the given number is: ", factorial)

*******************

You might also like