Skip to content

Instantly share code, notes, and snippets.

View MahraibFatima's full-sized avatar
:fishsticks:
striving

Mahraib Fatima MahraibFatima

:fishsticks:
striving
View GitHub Profile
@MahraibFatima
MahraibFatima / isAnagram.py
Created March 19, 2024 16:18
Determine whether the entered strings are anagrams or not.
def is_anagram(s1, s2):
return sorted(s1) == sorted(s2)
string1 = input("Enter the first string: ")
string2 = input("Enter the second string: ")
if is_anagram(string1, string2):
print("Anagrams")
else:
print("Not anagrams")
@MahraibFatima
MahraibFatima / FindLCM.py
Last active March 19, 2024 16:16
Compute the least common multiple of the two input numbers.
def compute_lcm(x, y):
if x > y:
greater = x
else:
greater = y
while True:
if greater % x == 0 and greater % y == 0:
lcm = greater
break
@MahraibFatima
MahraibFatima / countVowels.py
Created March 19, 2024 16:14
Count the number of vowels in the input string.
def count_vowels(s):
vowels = 'aeiouAEIOU'
count = 0
for char in s:
if char in vowels:
count += 1
return count
@MahraibFatima
MahraibFatima / isLeapYear.py
Created March 19, 2024 16:12
Determine whether the entered year is a leap year or not .
def is_leap_year(year):
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
return True
return False
year = int(input("Enter a year: "))
if is_leap_year(year):
print("Leap year")
else:
print("Not a leap year")
@MahraibFatima
MahraibFatima / temperatureConvertor.py
Created March 19, 2024 16:10
Convert the temperature from Celsius to Fahrenheit
celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = (celsius * 9/5) + 32
print("Temperature in Fahrenheit:", fahrenheit)
@MahraibFatima
MahraibFatima / Print_Table.py
Created March 19, 2024 16:09
Print the multiplication table for the entered number.
num = int(input("Enter a number: "))
for i in range(1, 11):
print(f"{num} x {i} = {num * i}")
@MahraibFatima
MahraibFatima / FindMaximum.py
Created March 19, 2024 16:08
Determine and print the largest number among the three numbers entered by the user.
a = float(input("Enter the first number: "))
b = float(input("Enter the second number: "))
c = float(input("Enter the third number: "))
max_num = max(a, b, c)
print("Largest number:", max_num)
@MahraibFatima
MahraibFatima / isPalindrome.py
Created March 19, 2024 16:06
Determine whether the entered string is a palindrome or not.
def is_palindrome(s):
return s == s[::-1]
string = input("Enter a string: ")
if is_palindrome(string):
print("Palindrome")
else:
print("Not a palindrome")
@MahraibFatima
MahraibFatima / FilteringNegativeNumbers.py
Created March 19, 2024 16:05
List containing only the positive numbers from the original list.
numbers = [-2, -1, 0, 1, 2, 3]
positive_numbers = [num for num in numbers if num >= 0]
print("Positive Numbers:", positive_numbers)
@MahraibFatima
MahraibFatima / CubingNumbers.py
Created March 19, 2024 16:03
List containing the cubes of numbers from 0 to 9.
cubes = [i ** 3 for i in range(10)]
print("Cubes:", cubes)