Programming Solutions
Programming Solutions
Solution:
def fibonacci(n):
a, b = 0, 1
while a < n:
a, b = b, a + b
2. Python program that computes the sum of all the elements of a list.
Solution:
def sum_of_list(lst):
return sum(lst)
Solution:
def reverse_string(s):
return s[::-1]
Solution:
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)
Solution:
def is_prime(n):
if n < 2:
return False
if n % i == 0:
return False
return True
Solution:
def sum_of_digits(num):
total = 0
total += num % 10
num //= 10
return total
Solution:
Solution:
def remove_duplicates(lst):
return list(set(lst))
Solution:
def sort_list(lst):
lst.sort()
return lst
Solution:
return lst.count(element)