Programming_Solutions_Full
Programming_Solutions_Full
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)
Solution:
def is_armstrong(num):
num_str = str(num)
num_digits = len(num_str)
12. Python program to generate a random number between two given numbers.
Solution:
import random
Solution:
def largest_number(lst):
return max(lst)
Solution:
def is_palindrome(s):
return s == s[::-1]
15. Python program to find the sum of even numbers in a given range.
Solution:
16. Python program to find the sum of digits of a number using recursion.
Solution:
def sum_of_digits(n):
if n == 0:
return 0
Solution:
import math
def is_perfect_square(n):
return math.isqrt(n) ** 2 == n
Solution:
def is_automorphic(n):
square = n * n
return str(square).endswith(str(n))
Solution:
def factorial_iterative(n):
result = 1
result *= i
return result
Solution:
21. Python program to find the length of a string without using the built-in len() function.
Solution:
def string_length(s):
count = 0
for char in s:
count += 1
return count
Solution:
def remove_vowels(s):
vowels = "aeiouAEIOU"
Solution:
def is_harshad_number(n):
return n % digit_sum == 0
Solution:
if exp == 0:
return 1
Solution:
import math
s = (a + b + c) / 2
return area