Python Slip 13 17 16.09
Python Slip 13 17 16.09
Slip No :- 13 B and 17 B
In [3]: # Slip No :- 13 B
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()
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.