Funny Puzzles of the Day

Write a Python program that prints the numbers from 1 to 100. For multiples of 3, print “Fizz” instead of the number. For multiples of 5, print “Buzz” instead of the number. For numbers that are multiples of both 3 and 5, print “FizzBuzz”.

Write a Python function that takes a string as input and returns True if the string is a palindrome (i.e., it reads the same forwards and backwards) and False otherwise.

Write a Python function that takes two strings as input and returns True if the strings are anagrams (i.e., they contain the same characters in a different order) and False otherwise.

Write a Python function that takes a string as input and returns the number of vowels (a, e, i, o, u) in the string.

Write a Python function that takes a list of integers as input and returns a list of all the integers that appear more than once in the input list.

I will be posting the solutions tomorrow for Batch DS301222

2 Likes

Hey!! Everyone who is checking this quiz out, you are free to try this out regardless of what batch you are from! :smile:

1 Like

DS301222

Write a Python program that prints the numbers from 1 to 100. For multiples of 3, print “Fizz” instead of the number.

For multiples of 5, print “Buzz” instead of the number.

For numbers that are multiples of both 3 and 5, print “FizzBuzz”.

for i in range(1, 101):
if i % 3 == 0 and i % 5 == 0:
print(“FizzBuzz”)
elif i % 3 == 0:
print(“Fizz”)
elif i % 5 == 0:
print(“Buzz”)
else:
print(i)

Write a Python function that takes a string as input and returns True

if the string is a palindrome (i.e., it reads the same forwards and backwards) and False otherwise.

srt1 = input("Enter a stirng : ")
srt1 = srt1.casefold()

rev_str = reversed(srt1)

if list(srt1) == list(rev_str):
print(“The string is a palindrome.”)
else:
print(“The string is not a palindrome.”)

Write a Python function that takes two strings as input and returns True

if the strings are anagrams (i.e., they contain the same characters in a different order)

and False otherwise

str1 = input("Enter string 1: ")
str2 = input("Enter string 2: ")

def isAnagram(str1, str2):
if sorted(str1) == sorted(str2):
return “The strings are anagrams.”
else:
return “The strings are not anagrams.”

print(isAnagram(str1, str2))

Write a Python function that takes a string as input and returns the number of vowels (a, e, i, o, u) in the string.

str1 = input("Enter string 1: ")

vowels = [“a”, “e”, “i”, “o”, “u”, “A”, “E”, “I”, “O”, “U”]
count = 0

for character in str1:
if character.lower() in vowels:
count += 1

print(f"Number of vowels (uppercase and lowercase) in the given string is: {count}")

Write a Python function that takes a list of integers as input

and returns a list of all the integers that appear more than once in the input list.

Python program to print duplicates from

a list of integers

lst_str = input("Enter a list of integers, separated by spaces: ")
lst = [int(x) for x in lst_str.split()]

unique_list = []
duplicate_list = []

for i in lst:
if i not in unique_list:
unique_list.append(i)
elif i not in duplicate_list:
duplicate_list.append(i)

print(“List of duplicates:”, duplicate_list)

3 Likes

Awesome spirit @prasadrnag :star_struck:!!

Correct Keep it up @prasadrnag

1 Like

for num in range(1, 101):
if num % 3 == 0 and num % 5 == 0:
print(“FizzBuzz”)
elif num % 3 == 0:
print(“Fizz”)
elif num % 5 == 0:
print(“Buzz”)
else:
print(num)

def is_palindrome(s):
s = s.lower().replace(’ ', ‘’)
for i in range(len(s)//2):
if s[i] != s[-i-1]:
return False
return True
print(is_palindrome(“racecar”)) # True
print(is_palindrome(“A man a plan a canal Panama”)) # True
print(is_palindrome(“hello world”)) # False

def is_anagram(s1, s2):
s1 = s1.lower().replace(’ ‘, ‘’)
s2 = s2.lower().replace(’ ', ‘’)
if len(s1) != len(s2):
return False
count1 = {}
count2 = {}
for char in s1:
count1[char] = count1.get(char, 0) + 1
for char in s2:
count2[char] = count2.get(char, 0) + 1
return count1 == count2
print(is_anagram(“listen”, “silent”)) # True
print(is_anagram(“triangle”, “integral”)) # True
print(is_anagram(“hello”, “world”)) # False

def count_vowels(s):
s = s.lower()
count = 0
for char in s:
if char in “aeiou”:
count += 1
return count
print(count_vowels(“hello world”)) # 3
print(count_vowels(“The quick brown fox jumps over the lazy dog”)) # 11
print(count_vowels(“Python is awesome”)) # 5

def find_duplicates(lst):
counts = {}
for num in lst:
if num in counts:
counts[num] += 1
else:
counts[num] = 1
duplicates = []
for num, count in counts.items():
if count > 1:
duplicates.append(num)
return duplicates
print(find_duplicates([1, 2, 3, 2, 4, 3, 5])) # [2, 3]
print(find_duplicates([1, 1, 1, 1, 1, 2, 2, 3, 3, 3])) # [1, 2, 3]
print(find_duplicates([1, 2, 3, 4, 5])) # []

1 Like

Good going @vaishu.swap10112016 Keep it up