This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def count_vowels(s): | |
vowels = 'aeiouAEIOU' | |
count = 0 | |
for char in s: | |
if char in vowels: | |
count += 1 | |
return count |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
celsius = float(input("Enter temperature in Celsius: ")) | |
fahrenheit = (celsius * 9/5) + 32 | |
print("Temperature in Fahrenheit:", fahrenheit) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
num = int(input("Enter a number: ")) | |
for i in range(1, 11): | |
print(f"{num} x {i} = {num * i}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_palindrome(s): | |
return s == s[::-1] | |
string = input("Enter a string: ") | |
if is_palindrome(string): | |
print("Palindrome") | |
else: | |
print("Not a palindrome") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
numbers = [-2, -1, 0, 1, 2, 3] | |
positive_numbers = [num for num in numbers if num >= 0] | |
print("Positive Numbers:", positive_numbers) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cubes = [i ** 3 for i in range(10)] | |
print("Cubes:", cubes) |
NewerOlder