Skip to content

Commit e100f88

Browse files
authored
Add files via upload
1 parent 3f3371d commit e100f88

File tree

10 files changed

+265
-0
lines changed

10 files changed

+265
-0
lines changed

10th.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import mysql.connector
2+
3+
# Define database connection details
4+
config = {
5+
'host': 'localhost',
6+
'user': 'your_username',
7+
'password': 'your_password',
8+
'database': 'example_db'
9+
}
10+
11+
# Connect to the database
12+
conn = mysql.connector.connect(**config)
13+
14+
# Create a cursor object to execute SQL queries
15+
c = conn.cursor()
16+
17+
# Create a table
18+
c.execute('''CREATE TABLE IF NOT EXISTS students
19+
(id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(255), age INT, email VARCHAR(255))''')
20+
21+
# Insert data into the table
22+
c.execute("INSERT INTO students (name, age, email) VALUES (%s, %s, %s)", ("John", 25, "[email protected]"))
23+
c.execute("INSERT INTO students (name, age, email) VALUES (%s, %s, %s)", ("Jane", 30, "[email protected]"))
24+
c.execute("INSERT INTO students (name, age, email) VALUES (%s, %s, %s)", ("Minhaj", 27, "[email protected]"))
25+
26+
# Commit changes to the database
27+
conn.commit()
28+
29+
# Query the table and fetch results
30+
c.execute("SELECT * FROM students")
31+
rows = c.fetchall()
32+
33+
# Print the results
34+
for row in rows:
35+
print(row)
36+
37+
# Close the database connection
38+
conn.close()

1st.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Q1. Write a Program to Demonstrate Different Data Types.
2+
3+
# Integer
4+
a = 10
5+
print("The value of a is:", a)
6+
print("The data type of a is:", type(a))
7+
8+
# Floating point number
9+
b = 3.14159
10+
print("The value of b is:", b)
11+
print("The data type of b is:", type(b))
12+
13+
# String
14+
c = "Hello, world!"
15+
print("The value of c is:", c)
16+
print("The data type of c is:", type(c))
17+
18+
# Boolean
19+
d = True
20+
print("The value of d is:", d)
21+
print("The data type of d is:", type(d))
22+
23+
# List
24+
e = [1, 2, 3, 4, 5]
25+
print("The value of e is:", e)
26+
print("The data type of e is:", type(e))
27+
28+
# Tuple
29+
f = (1, 2, 3, 4, 5)
30+
print("The value of f is:", f)
31+
print("The data type of f is:", type(f))
32+
33+
# Dictionary
34+
g = {"name": "John", "age": 30, "city": "New York"}
35+
print("The value of g is:", g)
36+
print("The data type of g is:", type(g))
37+

2nd.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
score = 75
2+
3+
if score >= 60:
4+
print("Congratulations, you passed the exam!")
5+
else:
6+
print("Sorry, you failed the exam. Please try again.")

3rd.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fruits = ["apple", "banana", "cherry"]
2+
for fruit in fruits:
3+
print(fruit)

4th.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
string = "hello world"
2+
3+
# capitalize() method
4+
print(string.capitalize())
5+
6+
# upper() method
7+
print(string.upper())
8+
9+
# lower() method
10+
print(string.lower())
11+
12+
# count() method
13+
print(string.count('l'))
14+
15+
# replace() method
16+
print(string.replace('world', 'python'))
17+
18+
# split() method
19+
print(string.split(' '))
20+
21+
# join() method
22+
words = ['hello', 'world']
23+
print(' '.join(words))

5th.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# function declaration
2+
def greet(name):
3+
print("Hello, " + name + "!")
4+
5+
# calling the function with argument
6+
greet("Alice")
7+
8+
# calling the function with another argument
9+
greet("Bob")

6th.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Parent class
2+
class Animal:
3+
def __init__(self, name):
4+
self.name = name
5+
6+
def speak(self):
7+
print(self.name + " makes a sound.")
8+
9+
# Child class (inheritance type: single inheritance)
10+
class Dog(Animal):
11+
def __init__(self, name):
12+
super().__init__(name)
13+
14+
def speak(self):
15+
print(self.name + " barks.")
16+
17+
# Child class (inheritance type: multi-level inheritance)
18+
class GoldenRetriever(Dog):
19+
def __init__(self, name):
20+
super().__init__(name)
21+
22+
def speak(self):
23+
print(self.name + " barks and wags its tail.")
24+
25+
# Child class (inheritance type: multiple inheritance)
26+
class Bird:
27+
def __init__(self, name):
28+
self.name = name
29+
30+
def speak(self):
31+
print(self.name + " chirps.")
32+
33+
class Parrot(Bird, Animal):
34+
def __init__(self, name):
35+
super().__init__(name)
36+
37+
def speak(self):
38+
print(self.name + " repeats words.")
39+
40+
# create objects of each class
41+
animal = Animal("Animal")
42+
dog = Dog("Dog")
43+
golden = GoldenRetriever("Golden Retriever")
44+
bird = Bird("Bird")
45+
parrot = Parrot("Parrot")
46+
47+
# call the speak method of each object
48+
animal.speak()
49+
dog.speak()
50+
golden.speak()
51+
bird.speak()
52+
parrot.speak()

7th.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Parent class
2+
class Animal:
3+
def __init__(self, name):
4+
self.name = name
5+
6+
def speak(self):
7+
print(self.name + " makes a sound.")
8+
9+
# Child class
10+
class Dog(Animal):
11+
def __init__(self, name):
12+
super().__init__(name)
13+
14+
def speak(self):
15+
print(self.name + " barks.")
16+
17+
# Child class
18+
class Cat(Animal):
19+
def __init__(self, name):
20+
super().__init__(name)
21+
22+
def speak(self):
23+
print(self.name + " meows.")
24+
25+
# create objects of each class
26+
animal = Animal("Animal")
27+
dog = Dog("Dog")
28+
cat = Cat("Cat")
29+
30+
# call the speak method of each object
31+
animal.speak()
32+
dog.speak()
33+
cat.speak()

8th.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
try:
2+
# ask user to input two numbers
3+
num1 = int(input("Enter the first number: "))
4+
num2 = int(input("Enter the second number: "))
5+
6+
# divide the first number by the second number
7+
result = num1 / num2
8+
9+
# print the result
10+
print("The result is:", result)
11+
12+
# handle exceptions that may occur
13+
except ValueError:
14+
print("Invalid input. Please enter a valid number.")
15+
16+
except ZeroDivisionError:
17+
print("Cannot divide by zero.")
18+
19+
except Exception as e:
20+
print("An error occurred:", e)
21+
22+
finally:
23+
print("Program completed.")

9th.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Lists
2+
fruits = ["apple", "banana", "cherry"]
3+
numbers = [1, 2, 3, 4, 5]
4+
5+
# Tuples
6+
person = ("John", 30, "Male")
7+
8+
# Sets
9+
colors = {"red", "green", "blue"}
10+
11+
# Dictionaries
12+
person_info = {
13+
"name": "John",
14+
"age": 30,
15+
"gender": "Male"
16+
}
17+
18+
# Accessing elements
19+
print(fruits[0]) # Output: "apple"
20+
print(person[1]) # Output: 30
21+
print(colors) # Output: {"red", "green", "blue"}
22+
print(person_info["name"]) # Output: "John"
23+
24+
# Modifying elements
25+
fruits[1] = "orange"
26+
person = ("Jane", 25, "Female")
27+
colors.add("yellow")
28+
person_info["age"] = 35
29+
30+
# Iterating through collections
31+
for fruit in fruits:
32+
print(fruit)
33+
34+
for number in numbers:
35+
print(number)
36+
37+
for color in colors:
38+
print(color)
39+
40+
for key, value in person_info.items():
41+
print(key, value)

0 commit comments

Comments
 (0)