Python Practical Slips

 BCA and BBA(C.A.) Practical Slips. Python practical slips  SPPU Practical Slips. Savitribai Phule Pune University

All Python Slips Solution:

Slip  1:

A) Write a Python program to accept n number in list and remove duplicates from a list.


Slip  2:

A) Write a Python function that accepts a string and calculate the number of upper case

letters and lower case letters.

Sample String: 'The quick Brown Fox'

Expected Output:

No. of Upper case characters: 3

No. of Lower case characters: 13


def calculate(str):
  dict={"uc":0,"lc":0}
  for num in str:
     if num.isupper():
       dict["uc"]+=1
     if num.islower():
       dict["lc"]+=1
  print("No. of Upper case characters:",dict["uc"])
  print("No. of Lower case characters:",dict["lc"])
string=input("Enter String: ")
calculate(string)

OR

dict={
    "a":1,
    "b":2,
    "c":3
}
key="a"
key_value=10
if key in dict:
    dict[key]=key_value
else:
    dict[key]=key_value
print(dict)


B)Write Python GUI program to create a digital clock with Tkinter to display the time.

import tkinter as tk
import time

def update_time():
    current_time = time.strftime("%H:%M:%S")
    clock_label.config(text=current_time)
    root.after(1000, update_time) # Update the time every second

root = tk.Tk()
root.title("Digital Clock")

clock_label = tk.Label(root, font=("Arial", 48), fg="black", bg="white")
clock_label.pack()

update_time()

root.mainloop()

Slip  3:

A) Write a Python program to check if a given key already exists in a dictionary. If

key exists replace with another key/value pair. 


dict={'Name':'Mahesh','Age':20}
key=input("Enter Key to check Exist or Not: ")
if key in dict:
  print('Key Exist')
  for key in dict.keys():
    pass
  key=input('Enter key :')
  value=input('Enter Value :')
  dict[key]=value
  print(dict)
else:
  print("Key not Exists")

#You can Use Following Program Also. Following Program checks Exists or Not at the Time
of Creating Dictionary.

dict={}
n=int(input('Enter How many Keys You Want:'))
for x in range(0,n):
  key=input('Enter Key:')
  if key in dict:
      for key in dict.keys():
           pass
      key=input('The Given Key Already Exists! Add Another Key')  
  value=input('enter the value :')
  dict[key]=value
print(dict)

B)

class Student:
    def __init__(self, roll_no, name, age, gender):
        self.roll_no = roll_no
        self.name = name
        self.age = age
        self.gender = gender

class Test(Student):
    def __init__(self, roll_no, name, age, gender, marks1, marks2, marks3):
        super().__init__(roll_no, name, age, gender)
        self.marks1 = marks1
        self.marks2 = marks2
        self.marks3 = marks3

    def display_details(self):
        total_marks = self.marks1 + self.marks2 + self.marks3
        print(f"Student Details:")
        print(f"Roll No: {self.roll_no}")
        print(f"Name: {self.name}")
        print(f"Age: {self.age}")
        print(f"Gender: {self.gender}")
        print(f"Total Marks: {total_marks}")

# Create three objects of the Test class
student1 = Test(1, "Alice", 15, "Female", 80, 90, 75)
student2 = Test(2, "Bob", 16, "Male", 70, 85, 90)
student3 = Test(3, "Charlie", 14, "Male", 90, 80, 70)

# Display the details of each student
student1.display_details()
student2.display_details()
student3.display_details()

Slip  4:

A) Write Python GUI program to create background with changing colors

import tkinter as tk
import random

def change_color():
  color = "#%06x" % random.randrange(0, 0xFFFFFF)
  root.config(bg=color)
  root.after(1000, change_color)
root = tk.Tk()
root.title("Changing Background")

change_color()
root.mainloop()



.

No comments: