week3
1.Aim: i) Write a program to convert a list and tuple
into arrays.
def convert(list):
return tuple(i for i in
list)
list = [1, 2, 3, 4]
print(convert(list))
OUTPUT:
(1, 2, 3, 4)
array1 = [1, 2, 3, 4, 5]
array2 = [4, 5, 6, 7, 8]
common_values = set(array1)&set(array2)
print("The common values between the two
arrays are:", list(common_values))
Output:
The common values between the two arrays are:
[4, 5]
Aim: ii) Write a program to find common values
between two arrays.
def gcd(a, b):
"""
Returns the greatest common divisor of two
integers a and b.
"""
while b != 0:
a, b = b, a % b
return a
print(gcd(12,8))
print(gcd(30,45))
2)Aim:Write a function called gcd that takes parameters a and
b and returns their greatest common divisor.
4
15
Output:
def isPalindrome(str):
for i in range(0, int(len(str)/2)):
if str[i] != str[len(str)-i-1]:
return False
return True
s = "malayalam"
ans = isPalindrome(s)
if (ans):
print("Yes")
else:
print("No")
3)Aim: Write a function called palindrome that takes a string
argument and returnsTrue if it is a palindrome and False
otherwise. Remember that you can use the built-in function len to
check the length of a string.
Yes
Output:

week3.pptx python related programs and outputs

  • 1.
  • 2.
    1.Aim: i) Writea program to convert a list and tuple into arrays. def convert(list): return tuple(i for i in list) list = [1, 2, 3, 4] print(convert(list)) OUTPUT: (1, 2, 3, 4)
  • 3.
    array1 = [1,2, 3, 4, 5] array2 = [4, 5, 6, 7, 8] common_values = set(array1)&set(array2) print("The common values between the two arrays are:", list(common_values)) Output: The common values between the two arrays are: [4, 5] Aim: ii) Write a program to find common values between two arrays.
  • 4.
    def gcd(a, b): """ Returnsthe greatest common divisor of two integers a and b. """ while b != 0: a, b = b, a % b return a print(gcd(12,8)) print(gcd(30,45)) 2)Aim:Write a function called gcd that takes parameters a and b and returns their greatest common divisor.
  • 5.
  • 6.
    def isPalindrome(str): for iin range(0, int(len(str)/2)): if str[i] != str[len(str)-i-1]: return False return True s = "malayalam" ans = isPalindrome(s) if (ans): print("Yes") else: print("No") 3)Aim: Write a function called palindrome that takes a string argument and returnsTrue if it is a palindrome and False otherwise. Remember that you can use the built-in function len to check the length of a string.
  • 7.