Professional Documents
Culture Documents
def multiply_list(numbers):
result = 1
result *= num
return result
output = multiply_list(sample_list)
def reverse_string(input_string):
return input_string[::-1]
sample_string = "1234abcd"
reversed_string = reverse_string(sample_string)
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)
n = 5 # Replace with the non-negative integer for which you want to calculate the factorial
result = factorial(n)
return True
else:
return False
Write a Python function that accepts a string and calculate the number of upper case letters and
lower case letters. Sample String : 'The quick Brow Fox' Expected Output : No. of Upper case
characters : 3 No. of Lower case Characters : 12
def count_upper_lower(string):
upper_count = 0
lower_count = 0
if char.isupper():
upper_count += 1
elif char.islower():
lower_count += 1
def unique_elements(input_list):
unique_list = []
unique_list.append(item)
return unique_list
sample_list = [1, 2, 3, 3, 3, 3, 4, 5]
result = unique_elements(sample_list)
def is_prime(number):
if number <= 1:
return False
if number % i == 0:
return False
return True
Write a Python function that checks whether a passed string is palindrome or not. Note: A
palindrome is a word, phrase, or sequence that reads the same backward as forward, e.g., madam or
nurses run.
def Pal(string):
left_pos = 0
right_pos = len(string) - 1
return False
left_pos += 1
right_pos -= 1
return True
print(Pal('racecar'))
Write a Python function that prints out the first n rows of Pascal's triangle. Note : Pascal's triangle is
an arithmetic and geometric figure first imagined by Blaise Pascal.
def print_pascals_triangle(n):
for i in range(n):
number = 1
number = number * (i - j) // (j + 1)
print()
print_pascals_triangle(n)
1
11
121
1331
14641