0% found this document useful (0 votes)
13 views6 pages

Python Number and Grade Calculations

The document contains a series of Python code snippets that demonstrate basic programming concepts such as checking even/odd numbers, finding the largest of three numbers, grading based on marks, determining leap years, checking positive/negative numbers, calculating the sum of natural numbers, multiplication tables, factorials, reversing numbers, and generating Fibonacci series. Each snippet includes user input and conditional statements to perform specific tasks. These examples serve as practical exercises for beginners in programming.

Uploaded by

aagarwalanshikaa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views6 pages

Python Number and Grade Calculations

The document contains a series of Python code snippets that demonstrate basic programming concepts such as checking even/odd numbers, finding the largest of three numbers, grading based on marks, determining leap years, checking positive/negative numbers, calculating the sum of natural numbers, multiplication tables, factorials, reversing numbers, and generating Fibonacci series. Each snippet includes user input and conditional statements to perform specific tasks. These examples serve as practical exercises for beginners in programming.

Uploaded by

aagarwalanshikaa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1.

num = int(input("Enter a number: "))

if num % 2 == 0:
print(num, "is even.")
else:
print(num, "is odd.")

2.
# Take three numbers as input from the user
a = int(input("Enter first number: "))

# Take second number as input


b = int(input("Enter second number: "))

# Take third number as input


c = int(input("Enter third number: "))

# Compare the numbers to find the largest


if a >= b and a >= c:
largest = a
elif b >= a and b >= c:
largest = b
else:
largest = c

# Print the largest number


print("The largest number is:", largest)
3.
# Take marks as input from the user
marks = float(input("Enter your marks: "))

# Determine the grade based on marks


if marks >= 90:
grade = 'A'
elif marks >= 80:
grade = 'B'
elif marks >= 70:
grade = 'C'
elif marks >= 60:
grade = 'D'
else:
grade = 'F'

# Print the grade


print("Your grade is:", grade)

4.
year = int(input("Enter a year: "))

if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):


print(year, "is a leap year")
else:
print(year, "is not a leap year")
5.

num = float(input("Enter a number: "))

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

6.

n = int(input("Enter a positive integer: "))


sum = 0

for i in range(1, n + 1):


sum += i

print("The sum of first", n, "natural numbers is:", sum)


7.
num = int(input("Enter a number: "))

for i in range(1, 11):


print(num, "x", i, "=", num * i)
8.

num = int(input("Enter a number: "))


factorial = 1

if num < 0:
print("Factorial is not defined for negative numbers.")
elif num == 0:
print("The factorial of 0 is 1.")
else:
for i in range(1, num + 1):
factorial *= i
print("The factorial of", num, "is:", factorial)

9.
num = int(input("Enter a number: "))
reverse = 0

while num != 0:
remainder = num % 10
reverse = reverse * 10 + remainder
num = num // 10

print("The reversed number is:", reverse)


10.
n = int(input("Enter the number of terms: "))
a=0
b=1

print("Fibonacci Series:")
for i in range(n):
print(a, end=" ")
a =b
b=a+b

You might also like