#Qn.1 reverse a string
def reverseString (text):
return text[::-1]
'hello world') reverseString (
'dlrow olleh'
Juma Shafara
May 1, 2023
python, python quiz, python data types, python functions, reverse string, palindrome checker, factorial calculator, fibonacci sequence, prime number checker, list reversal, anagram checker, finding unique elements
'dlrow olleh'
True
#Qn.3 Factorial Calculator
def numberFactorial(number):
if number==0 or number==1:
print(1)
else:
factorial = 1
for value in range (1, number+1):
factorial *= value
print(factorial)
numberFactorial(6)
720
Before we continue, we have a humble request, to be among the first to hear about future updates of the course materials, simply enter your email below, follow us on (formally Twitter), or subscribe to our YouTube channel.
#Qn.4 Fibonacci Sequence
def fibonacciSequence (number):
sequence = [0,1]
while len (sequence)< number:
sequence.append(sequence[-1] + sequence[-2])
return sequence
fibonacciSequence (8)
[0, 1, 1, 2, 3, 5, 8, 13]
#Qn.5 Prime Number Checker
def isPrimeNumber (number):
if number <= 1:
return False
for value in range(2,int(number**0.5)+1):
if number % value == 0:
return False
return True
isPrimeNumber(4)
False
[8, 6, 5, 3, 1]
#Qn.8 Anagram Checker
def areAnagram(string1, string2):
return sorted(string1) == sorted(string2)
areAnagram('listen','silent')
True
#Qn.9 Count words in a String
def countWords(string):
return len(string.split())
countWords('hello world')
2
#Qn.10 Unique Elements
def uniqueElements(list_):
return list(set(list_))
uniqueElements([2,4,3,2,6,4,7,9,5,3,5,1,6])
[1, 2, 3, 4, 5, 6, 7, 9]