Write A Python Function To Find The Max of Three Numbers
Write A Python Function To Find The Max of Three Numbers
Write A Python Function To Find The Max of Three Numbers
if x > y:
return x
return y
def max_of_three( x, y, z ):
print(max_of_three(3, 6, -5))
total = 0
for x in numbers:
total += x
return total
print(sum((8, 2, 3, 0, 7)))
total = 1
for x in numbers:
total *= x
return total
print(multiply((8, 2, 3, -1, 7)))
4. Write a Python program to reverse a string.
Sample String : "1234abcd"
Expected Output : "dcba4321"
Ans : def string_reverse(str1):
rstr1 = ''
index = len(str1)
while index > 0:
rstr1 += str1[ index - 1 ]
index = index - 1
return rstr1
print(string_reverse('1234abcd'))
if n == 0:
return 1
else:
return n * factorial(n-1)
n=int(input("Input a number to compute the factiorial : "))
print(factorial(n))
if n in range(3,9):
print( " %s is in the range"%str(n))
else :
print("The number is outside the given range.")
test_range(5)
8. Write a Python function that takes a list and returns a new list
with unique elements of the first list.
Sample List : [1,2,3,3,3,3,4,5]
Unique List : [1, 2, 3, 4, 5]
Ans : def unique_list(l):
x = []
for a in l:
if a not in x:
x.append(a)
return x
print(unique_list([1,2,3,3,3,3,4,5]))
if (n==1):
return False
elif (n==2):
return True;
else:
for x in range(2,n):
if(n % x==0):
return False
return True
print(test_prime(9))
10.Write a Python program to print the even numbers from a given
list.
Sample List : [1, 2, 3, 4, 5, 6, 7, 8, 9]
Expected Result : [2, 4, 6, 8]
Ans : def is_even_num(l):
enum = []
for n in l:
if n % 2 == 0:
enum.append(n)
return enum
print(is_even_num([1, 2, 3, 4, 5, 6, 7, 8, 9]))
sum = 0
for x in range(1, n):
if n % x == 0:
sum += x
return sum == n
print(perfect_number(6))
left_pos = 0
right_pos = len(string) - 1