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

Python Programs

python programs

Uploaded by

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

Python Programs

python programs

Uploaded by

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

PYTHON REVISION QUESTIONS – LOOPS and CONDITIONAL STATEMENTS

1. Program to identify weather it is negative number or positive number.

num = int(input(“Enter the number”))


if num > 0:
print("Positive number")
elif num == 0:
print("Zero")
else:
print("Negative number")

2. Program to print the largest of the three numbers

a = int(input("Enter a? "))
b = int(input("Enter b? "))
c = int(input("Enter c? "))
if a>b and a>c:
print("a is largest")
if b>a and b>c:
print("b is largest")
if c>a and c>b:
print("c is largest")

3.Program to accept numbers from the user and display the code

marks = int(input("Enter the marks? "))


if marks > 85 and marks <= 100:
print("Congrats ! you scored grade A ...")
elif marks > 60 and marks <= 85:
print("You scored grade B + ...")
elif marks > 40 and marks <= 60:
print("You scored grade B ...")
elif (marks > 30 and marks <= 40):
print("You scored grade C ...")
else:
print("Sorry you are fail ?")
4. Program to add natural numbers

n = int(input("Enter n: "))
sum = 0
i=1
while i <= n:
sum = sum + i
i = i+1
print("The sum is", sum)

5. To display the multiplication table of given number

num = int(input(“Enter the number”))


counter = 1
print("The Multiplication Table of: ", num)
while counter <= 10:
ans = num * counter
print (num, 'x', counter, '=', ans)

6. Program to display all even numbers till 100 using while


loop

7.Program to check whether a person is eligible to vote or not.

8. Program to check whether a number is even or not.

9. Python Program to Print Right Triangle using While Loop


10. Python Program to Print Inverted Right Triangle using While Loop
11. Print two half pyramids, one left half pyramid, and the second
downward left half pyramid.
12. Program to find the sum of all numbers stored in a list

13. Print individual letters of a string using the for loop


14. Using the for loop to iterate over a Python list

15. Nesting Python for loops

You might also like