0% found this document useful (0 votes)
67 views

Assingment Cs Printable

Programming exercises include menu driven programs for list manipulation, calculating statistical values from lists, swapping list elements, creating dictionaries to store student or sales data, and performing arithmetic operations on inputted numbers. More advanced problems involve checking file contents, binary file handling, random number generation using lists and integrating Python with SQL.

Uploaded by

stereogaming64
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)
67 views

Assingment Cs Printable

Programming exercises include menu driven programs for list manipulation, calculating statistical values from lists, swapping list elements, creating dictionaries to store student or sales data, and performing arithmetic operations on inputted numbers. More advanced problems involve checking file contents, binary file handling, random number generation using lists and integrating Python with SQL.

Uploaded by

stereogaming64
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/ 42

No.

Practical Date Signature


1 Write a python program to input a welcome message and display it
2 Write a python program to input two numbers and display the larger /
smaller number.
3 Write a python program to input three numbers and display the largest /
smallest number.
4 Generate the following patterns using nested loop

5 Write a program to count and display the number of vowels, consonants,


uppercase, lowercase characters in string.
6 Write a menu driven program for list manipulation. Display menu as:
1. Add a record
2. View record
3. Delete Record
4. Modify record
5. Exit
7 Write a menu drive program to the following from the list:
1. Maximum
2. Minimum
3. Sum
4. Sort in Ascending
5. Sort in Descending
6. Exit
8 Write a program to input a list of numbers and swap elements at the even
location with the elements at the odd location.
9 Write a program to Create a dictionary with the roll number, name and
marks of n students in a class and display the names of students who have
scored marks above 75.
10 Write a program to create a dictionary and store salesman name as a key
and sales of 3 months as values. Give the bonus to the salesman according
to the given criteria:
1. Total Sales < 10K – No Bonus
2. Total Sales 10K to 20K – 5%
3. Total Sales 21K to 30K – 8%
4. Total Sales 31K to 40K – 10%

11 Program to enter two numbers and print the arithmetic operations like +,-
,*, /, // and %.
12 Write a program to find whether an inputted number is perfect or not. S
13 Write a Program to check if the entered number is Armstrong or not.
14 Write a Program to find factorial of the entered number
15 Write a Program to enter the number of terms and to print the Fibonacci
Series.
16 Write a Program to enter the string and to check if it’s palindrome or not
using loop.
17 Read a file line by line and print it.
18 Remove all the lines that contain the character “a” in a file and write it
into another file.
19 Read a text file and display the number of
vowels/consonants/uppercase/lowercase characters in the file.
20 Create a binary file with name and roll no. Search for a given roll number
and display the name, if not found display appropriate message.
21 Write a random number generator that generates random numbers
between 1 and 6(simulates a dice)
22 Write a python program to implement a stack using a list data structure.

23 Take a sample of ten phishing emails (or any text file) and find most
commonly occurring word(s)
24 Read a text file line by line and display each word separated by a #
25 Create a student table and insert data. Implement the following SQL
commands on the student table:
• ALTER table to add new attributes / modify data type / drop attribute
• UPDATE table to modify data
• ORDER By to display data in ascending / descending order
• DELETE to remove tuple(s)
• GROUP BY and find the min, max, sum, count and averag
26 Integrate SQL with Python by importing the MySQL module

27 Integrate SQL with Python by importing the py mysql module.


28 Creating a Table
To create a table in MySQL, use the "CREATE TABLE" statement.
Make sure you define the name of the database when you create the
connection.
29 Database table of empl
Program01: Write a python program to input a welcome message and display it.
#Taking input
wl_msg = input(“Enter the welcome message:”)
#Printing Message print(wl_msg)

Output:

Program02: Write a python program to input two numbers and


display the larger / smaller number.
#Taking input
n1=int(input(“Enter number1 n1=input("Enter the first number
to check:")
n2=input("Enter the second number to check:")

#Checking Larger if n1>n2:


print(n1," is larger.") elif n2>n1:
print(n2," is larger") else: print("You have
entered equal number.")

#Checking Smaller if n1<n2:


print(n1," is smaller.") elif
n2<n1: print(n2," is smaller")
else:
print("You have entered equal number.")

Output:
Program03:Write a python program to input three
numbers and display the largest / smallest number.

n1=input("Enter the first number to check:")


n2=input("Enter the second number to check:")
n3=input("Enter the third number to check:")

#Checking Largest

if n1>n2 and n1>n3:


print(n1," is largest.")

elif n2>n1 and n2>n3:


print(n2," is largest")

elif n3>n1 and n3>n2:


print(n3," is largest")
else:
print("You have entered equal number.")

#Checking Smallest

if n1<n2 and n1<n3:


print(n1," is smallest.")

elif n2<n1 and n2<n3:


print(n2," is smallest")
elif n3<n1 and n3<n2:
print(n3," is smallest")
else:
print("You have entered equal number.")
Output:

Program04: Generate the following patterns using nested


loop.

#Code For Pattern1


for i in range(1,6):
for j in range(1,i+1):
print("*",end=" ")
print()

#Code for Pattern2


for i in range(6,1,-1
for j in range(1,i):

print(j,end=" ")
print()

#code for pattern 3


for i in range (65,70):
for j in range(65,i+1):
print(chr(j),end="")
print()
Program05:Write a program to count and display the number
of vowels, consonants, uppercase, lowercase characters in
string.

txt = input("Enter Your String : ")

v = c = uc = lc = 0

v_list =[‘a’,e,’I’,’o’,’u’]
for i in txt:
if i in v_list:

v += 1
if i not in v_list:

c += 1
if i.isupper():

uc += 1
if i.islower():

lc += 1

print("Number of Vowels in this text = ", v)

print("Number of Consonants in this text = ", c)

print("Number of Uppercase letters in this text=",


uc)

print("Number of Lowercase letters in this text=",


lc)

Output:
Program06: Write a menu driven program for list
manipulation .Display menu as:
1. Add a record
2. View record
3. Delete Record
4.Modify record 5. Exit
l=[] while True:
print('''1. Add a record
2. View record
3. Delete Record
4. Modify record 5. Exit''')
ch=int(input("Enter your choice:"))
if ch==1:
v=int(input("Enter value to add a record:"))
l.append(v)
print("Record Added...")
print("List after insertion:",l)
elif ch==2:
print(l)
elif ch==3:
n=int(input("Enter the value to
delete:"))
l.remove(n)
print("RecordDeleted...")
print("List after deletion:",l)
elif ch==4:
i=int(input("Enter position to modify the
value:"))
nv=int(input("Enter new value to modify:"))
print("Record Modified...")
print("List after modification”)
elif ch==5:
print(“Thank you! Good Bye”)
break
Output: Main Menu
Add record:

View Record:

Delete Record

Modify Record

Exit
Program07: Write a menu drive program to the
following from the list:
1. Maximum

2. Minimum

3. Sum

4. Sort in Ascending

5. Sort in Descending

6. Exit
l=[11,32,5,43,22,98,67,44]

while True:

print(''' 1. Maximum
2. Minimum
3. Sum
4. Sorting (Ascending)
5. Sorting (Descending) 6. Exit ''')
ch=int(input("Enter your choice:"))
if ch==1:
print("Maximum:",max(l))
elif ch==2:
print("Minimum:",min(l))
elif ch==3:
print("Sum:",sum(l))
elif ch==4:
l.sort()
print("Sorted list(Ascending):",l)
elif ch==5:
l.sort(reverse=True)
print("Sorted List(Descending:)",l)
elif ch==6:
print("Thank you! Good Bye")
break
Output:
Main menu

Maximum

Minimum

Sum

Sort (Ascending):

Sort(Descending):

Exit
Program08: Write a program to input a list of numbers
and swap elements at the even location with the
elements at the odd location.

l=eval(input("Enter a list: ")) print("Original

List before swapping:”,l) s=len(l)

if s%2!=0: s=s-1 for

i in range(0,s,2):

l[i],l[i+1]=l[i+1],l[i] print("List after


swapping the values :",l)

Output:
Program9: Write a program to Create a dictionary with
the roll number, name and marks of n students in a class
and display the names of students who have scored
marks above 75.

d={1:['Rudra',99],2:['Rushi',98],

3:['Prakash',65],4:['Jay',84]} for

i in d: if d[i][1]>75:

print(d[i][0]," \tscored -", d[i][1])

Output:
Program10: Write a program to create a dictionary and
store salesman name as a key and sales of 3 months as
values. Give the bonus to the salesman according to the
given criteria:
1. Total Sales < 1K – No
Bonus
2. Total Sales 1K to 2K –
5%
3. Total Sales 2.1K to 3K
– 8%
4. Total Sales 3.1K to 4K
– 10% 5. Total Sales
>4K – 12%
d={'Rudra':[199,180,540],'Rushi':[543,876,453],

'Preet':[650,987,123],'Jay':[284,456,321]}
bonus=0 for i in d:
d[i]=sum(d[i])
for i in d:
if d[i]<1000:
d[i]=0
elif d[i]>=1000 and d[i]<=2000:
d[i]=d[i]*0.05
elif d[i]>=2001 and d[i]<=3000:
d[i]=d[i]*0.08
elif d[i]>=3001 and d[i]<=4000:
d[i]=d[i]*0.1
elif d[i]>=4001:
d[i]=d[i]*0.12

print("Bonus for salesman:")


for i in d:
print(i,"\t: %.2f"%d[i])
Output:

Program 11: Program to enter two numbers and print the


arithmetic operations like +,-,*, /, // and %.

OUTPUT:
Program 12: Write a program to find whether an
inputted number is perfect or not.

OUTPUT:
Program 13: Write a Program to check if the entered
number is Armstrong or not.

Output:
Program 14: Write a Program to find factorial of the
entered number.

Output:
Program 15: Write a Program to enter the number
of terms and to print the Fibonacci
Series.

Output:
Program 16: Write a Program to enter the string and to
check if it’s palindrome or not using loop.

Output:

OR

Output: Yes
Program 17: Read a file line by line and print it.

Assume we have the following file, located in the same folder


as Python:

Output:
Program 18: Remove all the lines that contain the
character “a” in a file and write it into another file.

Assume we have the following file, located in the same folder


as Python:

Output:
Program 19: Read a text file and display the
number of
vowels/consonants/uppercase/lowercase
characters in the file.

Actual text file


Output:

Program 20: Create a binary file with name and


roll no. Search for a given roll number and display
the name, if not found display appropriate
message.
Output:
OR

Output:
Program 21: Write a random number generator
that generates random numbers between 1 and
6(simulates a dice)

Output:

Program 22: Write a python program to implement a


stack using a list data structure.

Stack Concept (SOURCE CODE):


Output:

Queue Concept (SOURCE CODE):

Output:
Program 23: Take a sample of ten phishing emails (or
any text file) and find most commonly occurring word(s)
Output:

Program 24: Read a text file line by line and display each
word separated by a #

Output:
Program 25: Create a student table and insert data.
Implement the following SQL commands on the
student table:

• ALTER table to add new attributes / modify data type / drop


attribute

• UPDATE table to modify data

• ORDER By to display data in ascending / descending order •

DELETE to remove tuple(s)

• GROUP BY and find the min, max, sum, count and average
SOURCE CODE:
Program 26: Integrate SQL with Python by
importing the MySQL module
Program 27: Integrate SQL with Python by
importing the py mysql module.
Program 28:Creating a Table
To create a table in MySQL, use the "CREATE TABLE"
statement.
Make sure you define the name of the database when you
create the connection.

SOURCE CODE
Program29: Database table of empl

• Calculate average salary of all employees listed in table


empl.
Source code
mysql> SELECT AVG(sal) "Average"
FROM empl;
Output: Average
12073.928571

• Count number of records in table empl Solution.


Source code
mysql> SELECT COUNT(*) "Total"
FROM emp);
Output Total
14

You might also like