0% found this document useful (0 votes)
2 views4 pages

Computer python project

The document contains four Python programs demonstrating basic programming concepts. The first program checks if a number is even or odd, the second categorizes a person by age, the third prints a multiplication table, and the fourth calculates the sum of the first N natural numbers. Each program includes code snippets and example outputs.

Uploaded by

maitiritveek
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)
2 views4 pages

Computer python project

The document contains four Python programs demonstrating basic programming concepts. The first program checks if a number is even or odd, the second categorizes a person by age, the third prints a multiplication table, and the fourth calculates the sum of the first N natural numbers. Each program includes code snippets and example outputs.

Uploaded by

maitiritveek
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
You are on page 1/ 4

Program 1: If-else Statement-Based

Program
Question: Write a program to check if a given number is
even or odd.
Code:

Python:
num = int(input("Enter a number: "))
if num % 2 == 0:
print(f"{num} is an even number.")
else:
print(f"{num} is an odd number.")

Output Example:
Enter a number: 7
7 is an odd number.
Program 2: If-else Statement-Based
Program
Question: Write a program to categorize a person based on
their age.
Code:

Python:
age = int(input("Enter your age: "))
if age < 13:
print("You are a Child.")
elif age < 20:
print("You are a Teenager.")
elif age < 60:
print("You are an Adult.")
else:
print("You are a Senior Citizen.")

Output Example:
mathematica
CopyEdit
Enter your age: 25
You are an Adult.
Program 3: For Loop / While Loop-Based
Program
Question: Write a program to print the multiplication table of a
given number using a for loop.
Code:

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

print(f"Multiplication table for {num}:")


for i in range(1, 11):
print(f"{num} x {i} = {num * i}")

Output Example:
Enter a number: 5
Multiplication table for 5:
5x1=5
5 x 2 = 10
...
5 x 10 = 50
Program 4: Series Program
Question: Write a program to calculate the sum of the first N
natural numbers.
Code:

python
n = int(input("Enter the value of N: "))
# Using the formula for the sum of first N natural numbers
sum_n = n * (n + 1) // 2
print(f"The sum of the first {n} natural numbers is {sum_n}.")

Output Example:
Enter the value of N: 10
The sum of the first 10 natural numbers is 55.

You might also like