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

Python Slip 13 17 16.09

Uploaded by

arpitamohan3005
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Python Slip 13 17 16.09

Uploaded by

arpitamohan3005
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Date : - 16/09/24

Slip No :- 13 B and 17 B

In [3]: # Slip No :- 13 B

n=int(input("Enter size of queue: "))


print("Enter elements of queue: ")
mylist=list()
for i in range(n):
ele=input()
mylist.append(ele)
print("Current queue:- ")
print(mylist)
print("\n")
for j in range(len(mylist)):
print(mylist)
pop_ele=mylist.pop(0)
print(pop_ele)

Enter elements of queue:


Current queue:-
['10', '20', '30', '40', '50']

['10', '20', '30', '40', '50']


10
['20', '30', '40', '50']
20
['30', '40', '50']
30
['40', '50']
40
['50']
50

In [ ]: # Logic:-

The code then collects these elements from the user and stores them in a list called mylist.
After displaying the current state of the queue, the code processes the queue by repeatedly removing and printing the first element until the queue is empty.
During each iteration of the loop, it shows the current state of the queue before and after removing the element, and then prints the removed element.
This approach simulates basic queue operations using a list, where the first element added is the first one to be removed,
following the FIFO (First In, First Out) principle.

In [12]: # Slip :- 17 B

class date:
def acceptdate(self):
self.day=int(input("Enter Day: "))
self.month=int(input("Enter Month: "))
self.year=int(input("Enter Year: "))
def printdate(self):
try:
if(self.day>31):
raise Exception("Day value is greater than 31")
if(self.month>12):
raise Exception("Month value is greater than 12")

if(self.year<0):
raise Exception("Year value should not be negative")
print("Date: ",self.day,"-",self.month,"-",self.year)
except Exception as e:
print(e)
objdate=date()
objdate.acceptdate()
objdate.printdate()

Month value is greater than 12

In [ ]: # Logic: -

This Python code defines a class named `date` with two methods: `acceptdate` and `printdate`.
The `acceptdate` method prompts the user to input a day, month, and year, which are stored as instance variables.
The `printdate` method checks if the entered values are within valid ranges—days should not exceed 31,
months should not exceed 12, and the year should not be negative.
If any of these conditions are violated, it raises an exception with an appropriate error message.
If all values are valid, it prints the date in a `day-month-year` format.
An instance of the `date` class is created, and both methods are called to accept user input and display the date, handling any input errors gracefully.

You might also like