Practiceset 2
Practiceset 2
Nikhil Rai
22BCE11442
oUTPUT
Deposited $500. New balance: $1500
Withdrew $200. New balance: $1300
Account balance for John Doe (Account #123456789): $1300
Q2) Write a Python class that has two methods: get_String and
print_String , get_String accept a string from the user and
print_String prints the string in upper case.
Code
class StringManipulator:
def __init__(self):
self.user_string = ""
def get_string(self):
self.user_string = input("Enter a string: ")
def print_string_uppercase(self):
print("Uppercase String:", self.user_string.upper())
if(__name__ == "__main__"):
# Creating an instance of StringManipulator
string_manipulator = StringManipulator()
# Getting a string from the user
string_manipulator.get_string()
# Printing the entered string in uppercase
string_manipulator.print_string_uppercase()
oUTPUT
Enter a string: hello everyone
Uppercase String: HELLO EVERYONE
oUTPUT
Area of the circle with radius 5: 78.54
Perimeter of the circle with radius 5: 31.42
Q4) Create a Python class called “Car” with attributes like make,
model, and year. Then, create an object of the “Car” class and
print its details.
Code
class Car:
def __init__(self, make, model, year):
self.make=make
self.model=model
self.year=year
def display_details(self):
print(f"Car Details:\nMake: {self.make}\nModel:{self.model}\nYear:
{self.year}")
if(__name__ == "__main__"):
# Creating an instance of the Car class
car1=Car(make="Toyota", model="Camry", year=2022)
# Displaying the details of the car
car1.display_details()
oUTPUT
Car Details:
Make: Toyota
Model: Camry
Year: 2022
oUTPUT
The factorial of 5 is: 120
8 is an even number.