**Report File**
---
### Section 1: Python Programs
#### Question 1: Write a program to print "Hello, World!"
```python
print("Hello, World!")
```
#### Question 2: Write a program to calculate the sum of two numbers.
```python
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("Sum:", a + b)
```
#### Question 3: Write a program to find the factorial of a number.
```python
def factorial(n):
return 1 if n == 0 else n * factorial(n-1)
num = int(input("Enter a number: "))
print("Factorial:", factorial(num))
```
#### Question 4: Write a program to generate a Fibonacci series.
```python
def fibonacci(n):
a, b = 0, 1
for _ in range(n):
print(a, end=" ")
a, b = b, a + b
n = int(input("Enter number of terms: "))
fibonacci(n)
```
#### Question 5: Write a program to check if a string is a palindrome.
```python
def is_palindrome(string):
return string == string[::-1]
s = input("Enter a string: ")
print("Palindrome:", is_palindrome(s))
```
#### Question 6: Write a program to check if a number is prime.
```python
def is_prime(n):
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
num = int(input("Enter a number: "))
print("Prime:", is_prime(num))
```
#### Question 7: Write a program to reverse a string.
```python
s = input("Enter a string: ")
print("Reversed string:", s[::-1])
```
#### Question 8: Write a program to find the largest number in a list.
```python
nums = list(map(int, input("Enter numbers separated by spaces: ").split()))
print("Largest number:", max(nums))
```
#### Question 9: Write a program to count vowels in a string.
```python
s = input("Enter a string: ")
vowels = "aeiouAEIOU"
count = sum(1 for char in s if char in vowels)
print("Number of vowels:", count)
```
#### Question 10: Write a program to implement bubble sort.
```python
def bubble_sort(arr):
n = len(arr)
for i in range(n):
for j in range(0, n-i-1):
if arr[j] > arr[j+1]:
arr[j], arr[j+1] = arr[j+1], arr[j]
arr = list(map(int, input("Enter numbers separated by spaces: ").split()))
bubble_sort(arr)
print("Sorted array:", arr)
```
#### Question 11: Write a program to calculate BMI.
```python
weight = float(input("Enter weight in kg: "))
height = float(input("Enter height in meters: "))
bmi = weight / (height ** 2)
print("BMI:", bmi)
```
#### Question 12: Write a program to check if a number is an Armstrong number.
```python
def is_armstrong(num):
digits = [int(d) for d in str(num)]
return num == sum(d ** len(digits) for d in digits)
num = int(input("Enter a number: "))
print("Armstrong:", is_armstrong(num))
```
#### Question 13: Write a program to calculate simple interest.
```python
principal = float(input("Enter principal amount: "))
rate = float(input("Enter rate of interest: "))
time = float(input("Enter time in years: "))
interest = (principal * rate * time) / 100
print("Simple Interest:", interest)
```
#### Question 14: Write a program to generate a multiplication table.
```python
num = int(input("Enter a number: "))
for i in range(1, 11):
print(f"{num} x {i} = {num * i}")
```
#### Question 15: Write a program to check if two strings are anagrams.
```python
def are_anagrams(str1, str2):
return sorted(str1) == sorted(str2)
s1 = input("Enter first string: ")
s2 = input("Enter second string: ")
print("Anagrams:", are_anagrams(s1, s2))
```
---
### Section 2: SQL Queries
#### Table: `employees`
| emp_id | name | department | salary |
|--------|------------|------------|--------|
|1 | John | HR | 50000 |
|2 | Alice | IT | 60000 |
|3 | Bob | Sales | 55000 |
|4 | Clara | IT | 65000 |
#### Query 1: Select All Records
```sql
SELECT * FROM employees;
```
#### Query 2: Employees with Salary Greater Than 55000
```sql
SELECT * FROM employees WHERE salary > 55000;
```
#### Query 3: Count Employees in Each Department
```sql
SELECT department, COUNT(*) AS employee_count FROM employees GROUP BY department;
```
#### Query 4: Update Salary for IT Department
```sql
UPDATE employees SET salary = salary * 1.10 WHERE department = 'IT';
```
#### Query 5: Join Example (Using Two Tables)
Assume a second table `projects`:
| proj_id | emp_id | project_name |
|---------|--------|--------------|
| 101 |1 | Project A |
| 102 |2 | Project B |
| 103 |3 | Project C |
Query:
```sql
SELECT employees.name, projects.project_name
FROM employees
JOIN projects ON employees.emp_id = projects.emp_id;
```
---
### Section 3: Python-SQL Connectivity
#### Question 1: Write a program to connect to SQLite database.
```python
import sqlite3
conn = sqlite3.connect('example.db')
print("Connected to database")
conn.close()
```
#### Question 2: Write a program to create a table and insert data.
```python
import sqlite3
conn = sqlite3.connect('example.db')
cursor = conn.cursor()
cursor.execute('''CREATE TABLE IF NOT EXISTS employees (emp_id INTEGER, name TEXT,
department TEXT, salary REAL)''')
cursor.execute('''INSERT INTO employees VALUES (1, 'John', 'HR', 50000)''')
conn.commit()
print("Table created and data inserted")
conn.close()
```
#### Question 3: Write a program to fetch records from the database.
```python
import sqlite3
conn = sqlite3.connect('example.db')
cursor = conn.cursor()
cursor.execute('''SELECT * FROM employees''')
rows = cursor.fetchall()
for row in rows:
print(row)
conn.close()
```
#### Question 4: Write a program to update records in the database.
```python
import sqlite3
conn = sqlite3.connect('example.db')
cursor = conn.cursor()
cursor.execute('''UPDATE employees SET salary = salary + 5000 WHERE department = 'HR' ''')
conn.commit()
print("Records updated")
conn.close()
```