0% found this document useful (0 votes)
3 views2 pages

Assignment 1 Python Programs

The document contains three Python programming assignments. The first assignment checks if a number is even or odd, the second generates the Fibonacci series up to 100, and the third reads a CSV file and visualizes the data using various plots. Each program includes necessary code snippets and comments for clarity.

Uploaded by

justin kit
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)
3 views2 pages

Assignment 1 Python Programs

The document contains three Python programming assignments. The first assignment checks if a number is even or odd, the second generates the Fibonacci series up to 100, and the third reads a CSV file and visualizes the data using various plots. Each program includes necessary code snippets and comments for clarity.

Uploaded by

justin kit
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
You are on page 1/ 2

Assignment 1

Q1. Python Program to Find if a Number is Even or Odd

```python
# Program to check if the number is even or odd

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

if num % 2 == 0:
print(f"{num} is Even")
else:
print(f"{num} is Odd")
```
------------------------------------------------------------

Q2. Python Program to Find the Fibonacci Series up to 100

```python
# Program to generate Fibonacci series up to 100

a, b = 0, 1
print("Fibonacci series up to 100:")

while a <= 100:


print(a, end=" ")
a, b = b, a + b
```
------------------------------------------------------------

Q3. Python Program to Read a CSV File and Visualize Data

```python
# Make sure to install pandas and matplotlib before running:
# pip install pandas matplotlib

import pandas as pd
import matplotlib.pyplot as plt

# Read CSV file (replace 'data.csv' with your file path)


file_path = 'data.csv' # Example: 'C:/Users/YourName/Downloads/data.csv'
data = pd.read_csv(file_path)

# Display the first few rows


print("Data Preview:")
print(data.head())

# Visualization examples (adjust based on your CSV columns)


# 1. Line plot
data.plot()
plt.title("Line Plot of All Numeric Columns")
plt.show()
Assignment 1

# 2. Histogram of a specific column (replace 'ColumnName')


if 'ColumnName' in data.columns:
data['ColumnName'].hist(bins=10)
plt.title("Histogram of ColumnName")
plt.xlabel("Value")
plt.ylabel("Frequency")
plt.show()

# 3. Bar plot of first 10 rows for a column (adjust names as needed)


if 'XColumn' in data.columns and 'YColumn' in data.columns:
data.head(10).plot(kind='bar', x='XColumn', y='YColumn')
plt.title("Bar Chart of First 10 Entries")
plt.show()
```

You might also like