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

Python & SQL Programming Examples

Uploaded by

Vaibhav Yadav
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)
7 views2 pages

Python & SQL Programming Examples

Uploaded by

Vaibhav Yadav
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

Python Programming & SQL Report

15 Python Programs
1. Program to print Hello World
print('Hello World')

2. Program to add two numbers


a=5
b=3
print(a+b)

3. Program to check even/odd


n=7
print('Even' if n%2==0 else 'Odd')

4. Program to find factorial


import math
print([Link](5))

5. Program for simple interest


p=1000;r=5;t=2
print(p*r*t/100)

6. Fibonacci series
n=5
a,b=0,1
for _ in range(n): print(a); a,b=b,a+b

7. Reverse a string
s='hello'
print(s[::-1])

8. Check palindrome
s='madam'
print('Palindrome' if s==s[::-1] else 'Not')

9. Largest of three
print(max(10,20,30))

10. Sum of list


lst=[1,2,3]
print(sum(lst))

11. Count vowels


s='computer'
print(sum(c in 'aeiou' for c in s))

12. Table of a number


n=5
for i in range(1,11): print(n*i)

13. Armstrong number


n=153
print(n==sum(int(d)**3 for d in str(n)))

14. Prime check


n=7
print(all(n%i for i in range(2,n)))

15. File write example


f=open('[Link]','w');[Link]('Hello');[Link]()

4 SQL Connectivity Programs


1. MySQL Connection
import [Link]
con=[Link](host='localhost',user='root',password='',database='test')

2. Create Table
cur=[Link]()
[Link]('CREATE TABLE student(id INT,name VARCHAR(20))')

3. Insert Data
[Link]("INSERT INTO student VALUES(1,'Ram')")
[Link]()

4. Fetch Data
[Link]('SELECT * FROM student')
print([Link]())

5 SQL Queries
1. SELECT * FROM student;

2. SELECT name FROM student WHERE id=1;

3. UPDATE student SET name='Shyam' WHERE id=1;

4. DELETE FROM student WHERE id=1;

5. SELECT COUNT(*) FROM student;

You might also like