We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12
Introduction
• Overview: In this presentation, we will cover
several basic Python programs, including checking even/odd numbers, finding maximum numbers, and more.
Photo by Christina @ wocintechchat.com on Unsplash
Check if the Input Number is Even or Odd
• Program Code: ```python def
check_even_odd(num): if num % 2 == 0: return 'Even' else: return 'Odd' num = int(input('Enter a number: ')) print(check_even_odd(num)) ```
Photo by Ilija Boshkov on Unsplash
Find the Maximum Number Between Two Numbers
• Program Code: ```python def find_maximum(a,
b): if a > b: return a else: return b num1 = int(input('Enter first number: ')) num2 = int(input('Enter second number: ')) print('Maximum number is:', find_maximum(num1, num2)) ```
Photo by Mika Baumeister on Unsplash
Find the Maximum Number Between Three Numbers
• Program Code: ```python def find_maximum(a,
b, c): if a >= b and a >= c: return a elif b >= a and b >= c: return b else: return c num1 = int(input('Enter first number: ')) num2 = int(input('Enter second number: ')) num3 = int(input('Enter third number: ')) print('Maximum number is:', find_maximum(num1, num2, num3)) ```
Photo by Mika Baumeister on Unsplash
Print Input Day Name Corresponding to Day Number
• Program Code: ```python def
get_day_name(day_num): days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] if 1 <= day_num <= 7: return days[day_num - 1] else: return 'Invalid day number' day_num = int(input('Enter day number (1-7): ')) print('Day name is:', get_day_name(day_num)) ```
Photo by Amanda Jones on Unsplash
Check Whether a Number is Negative or Positive
• Program Code: ```python def
check_number(num): if num > 0: return 'Positive' elif num < 0: return 'Negative' else: return 'Zero' num = float(input('Enter a number: ')) print('The number is:', check_number(num)) ```
Photo by Amanda Jones on Unsplash
Check Whether a Number is Divisible by 5 and 11
• Program Code: ```python def
check_divisibility(num): if num % 5 == 0 and num % 11 == 0: return 'Divisible by both 5 and 11' else: return 'Not divisible by both 5 and 11' num = int(input('Enter a number: ')) print(check_divisibility(num)) ```
Photo by Tony Hand on Unsplash
Check Whether an Input Character is an Alphabet
• Program Code: ```python def is_alphabet(char):
if char.isalpha(): return 'Alphabet' else: return 'Not an alphabet' char = input('Enter a character: ') print(is_alphabet(char)) ```
Photo by Alexander Andrews on Unsplash
Check Whether an Input Character is a Vowel or Consonant
• Program Code: ```python def
is_vowel_or_consonant(char): vowels = 'aeiouAEIOU' if char in vowels: return 'Vowel' else: return 'Consonant' char = input('Enter a character: ') print(is_vowel_or_consonant(char)) ```
Photo by Amanda Jones on Unsplash
Check Whether a Character is Uppercase or Lowercase
• Program Code: ```python def check_case(char): if
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0): return 'Leap year' else: return 'Not a leap year' year = int(input('Enter a year: ')) print(is_leap_year(year)) ```
Photo by San Kayzen on Unsplash
Conclusion
• Summary: We covered various basic Python
programs including checking even/odd numbers, finding maximum numbers, checking alphabets, vowels, cases, and leap years.
Photo by Christina @ wocintechchat.com on Unsplash