Python Lab File Activities
Python Lab File Activities
Code:
primes = []
if num % i == 0:
break
else:
primes.append(num)
return primes
Output:
Prime numbers between 10 and 50: [11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
Title: Python program to check whether a number is Prime or not
Code:
def is_prime(num):
if num <= 1:
return False
if num % i == 0:
return False
return True
Output:
Is 29 prime? True
Title: Python Program for nth Fibonacci number
Code:
def fibonacci(n):
if n <= 0:
return 0
elif n == 1:
return 1
else:
Output:
def is_fibonacci(num):
x1 = 5 * num ** 2 + 4
x2 = 5 * num ** 2 - 4
Output:
n = len(arr)
Output:
n = len(arr)
k=k%n
arr[:k] = reversed(arr[:k])
arr[k:] = reversed(arr[k:])
arr.reverse()
return arr
Output:
Output:
product = 1
return product
Output:
def multiply_list(lst):
result = 1
result *= num
return result
Output:
Product of list: 24
Title: Python program to find smallest number in a list
Code:
def smallest_in_list(lst):
return min(lst)
Output: