Python
Python
Python
list=PLhQjrBD2T3817j24-GogXmWqO5Q5vYy0V
2. Odd or Even:
Write a program that takes an integer and checks if it is odd or even.
num = int(input('Enter a number: '))
if num % 2 == 0:
print('The number is even')
else:
print('The number is odd')
4. Check Divisibility:
Write a program that takes an integer and checks if it is divisible by 5 and 11.
num = int(input('Enter a number: '))
if num % 5 == 0 and num % 11 == 0:
print('The number is divisible by both 5 and 11')
elif num % 5 == 0 or num % 11 == 0:
print('The number is divisible by 5 or 11')
else:
print('The number is not divisible by 5 or 11')
5. Check for Leap Year:
Write a program that takes a year as input and checks if it is a leap year.
year = int(input('Enter a year: '))
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print(f'{year} is a leap year')
else:
print(f'{year} is not a leap year')
7. Grade Calculator:
Write a program that takes a score as input and prints the corresponding grade
based on the following ranges:
- 90-100: A
- 80-89: B
- 70-79: C
- 60-69: D
- Below 60: F
score = int(input('Enter your score: '))
if score >= 90:
print('Grade: A')
elif score >= 80:
print('Grade: B')
elif score >= 70:
print('Grade: C')
elif score >= 60:
print('Grade: D')
else:
print('Grade: F')
8. Check Palindrome:
Write a program that takes a string and checks if it is a palindrome.
word = input('Enter a word: ')
if word == word[::-1]:
print('The word is a palindrome')
else:
print('The word is not a palindrome')
2. 𝗳𝗶𝗹𝗹𝗻𝗮(): Replace missing values with a specified value or method. With the help
of df.fillna(value) you maintain data integrity without losing valuable information.
5. 𝗮𝘀𝘁𝘆𝗽𝗲(): Convert data types for consistency and accuracy. Use the cast
function df['column'].astype(dtype) to ensure your data columns are in the correct
format you need for your analysis.
Types of Polymorphism
Compile-Time Polymorphism (Method Overloading) This type of polymorphism
occurs when multiple methods within a class have the same name but different
parameters. For example, based on the arguments provided, a drawing method
could be overloaded to draw various shapes, such as circles, rectangles, or
triangles.
Run-Time Polymorphism (Method Overriding): This occurs when a subclass
provides a specific implementation for a method that is already provided by its
parent class. This way, the method behaves differently depending on the object that
invokes it. For instance, a generic Vehicle class method start() could be overridden
by Car and Bike subclasses to start a car or bike specifically.