Python_Exercises_with_Examples
Python_Exercises_with_Examples
def fibonacci_series(n):
a, b = 0, 1
for _ in range(n):
print(a, end=" ")
a, b = b, a + b
Example:
Input: 5
Output: 0 1 1 2 3
def is_palindrome(s):
return s == s[::-1]
Example:
Input: 'madam'
Output: madam is a palindrome.
def roll_dice():
return random.randint(1, 6)
Example:
# library.py
def add(a, b):
return a + b
# main.py
import library
print(library.add(5, 3))
print(library.subtract(5, 3))
Example:
Output: 8
2
Example: