The document contains multiple Python programs that perform various tasks such as calculating the sum of the first five natural numbers, grading students based on their marks, finding the greatest of three numbers, checking if a number is even or odd, and determining voting eligibility. It also includes programs to check if a number is greater than zero, print even numbers in a given range, and generate a list from 1 to 20. Each program includes user input and conditional statements to execute the desired functionality.
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 ratings0% found this document useful (0 votes)
4 views4 pages
ProgramS-Contril Structure in Python
The document contains multiple Python programs that perform various tasks such as calculating the sum of the first five natural numbers, grading students based on their marks, finding the greatest of three numbers, checking if a number is even or odd, and determining voting eligibility. It also includes programs to check if a number is greater than zero, print even numbers in a given range, and generate a list from 1 to 20. Each program includes user input and conditional statements to execute the desired functionality.
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/ 4
#Program to add first 5 natural numbers
sum = 0
a=1
while (a<=5):
sum = sum + a
a=a+1
print("The sum of first five natural num is", sum)
#Program to grade a student based on his/her marks
marks = int(input("Enter your marks: "))
if (marks >= 90):
print("A grade")
elif (marks >= 80):
print("B grade")
elif (marks >= 70):
print("C grade")
elif (marks >= 60):
print("D grade")
elif (marks >= 50):
print("You can do better")
else:
print("You need to work hard")
#Program to check greatest of the three numbers
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
num3 = int(input("Enter the third number: "))
if num1 > num2:
if num1 > num3:
print("Num1 is greatest Number ;", num1)
else:
print("Num3 is greatest Number ;", num1)
else: if num2 > num3:
print("Num2 is greatest Number ;", num2)
else:
print("Num3 is greatest Number ;", num3)
print("Num3 is greatest Number ;", num1)
#To check whether the entered number is even or odd n = int(input("Enter your number: ")) if (n%2) == 0: print("The entered number is even") else: print("The entered number is odd") #To check whether a person can vote age = 18 if (age<18): print ("You are eligible to cast your vote") else: print ("You are not eligible to cast your vote") #To check whether the given number is greater than zero. n =int(input("Enter a Number: ")) if n > 0: print ("The entered number is greater than 0") else: print("The entered number is smaller than 0") # Python program to print Even Numbers in given range Start = int(input("Enter the start of range: ")) end = int(input("Enter the end of range: ")) # iterating each number in list for num in range(start, end + 1): # checking condition if num % 2 == 0: print(num, end=" ") # Program to check whether the number is positive or negative a = int(input("Enter the number to test: ")) if (a>0): else: print("The given number is a negative number") # Program to generate a list from 1-20 for n in range(1, 21): print(n)’