Untitled
unknown
plain_text
a year ago
1.1 kB
3
Indexable
Q.1 def rotate(string, increment): result = "" for i in string: if (i != " "): ch1 = ord(i) ch1 += increment ch1 = chr(ch1) result += ch1 return result string = input("Enter the string for rotation:") increment = int(input('Enter the increment number:')) result = rotate(string, increment) print(f'The original string {string} after rotation by {increment} is {result}.') Q.2 def chrToString(chrLst): result = "" for i in chrLst: result += i return result n = int(input("How many characters you want in your list:")) chrLst = [] for i in range(n): char = input('Enter the character:') if(len(char) == 1): chrLst.append(char) else: print('Enter a single character not a string.') result = chrToString(chrLst) print(result) Q. 3 def findIndex(lst, reqElmnt): return lst.index(reqElmnt) lst = ["cat", "dog", "elephant", "horse", "rabbit", "cow"] reqElmnt = input('Enter the element you want the index of:') print(f'The index of {reqElmnt} in the list is: {findIndex(lst, reqElmnt)}')
Editor is loading...
Leave a Comment