Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

python 3. Write function, maxChar(inputString) that takes as input a string of o

ID: 3665294 • Letter: P

Question

python 3. Write function, maxChar(inputString) that takes as input a string of one or more lower case letters and prints information about the lexicographically largest character in the string along with the index of the first occurrence of that character. Important: your function must contain a loop and you must determine the index of the character within the loop (i.e. you may not use Python's index or similar built-in function) For example maxC har ("abrcdefxyqurslajelskd") should yield: The max char is 'y' and occurs at position 8. to the binary representation of the input number. Assume the input number is an integer equal to or greater than zero. 4. Write a function, binaryRepString(number), that returns a string containing only '1's and '0's corresponding to the binary representation of the input number. Assume the input number is an integer equal to or greater than zero. For example, binaryRepString(0) should return 0, binaryRepString(2) should return '10', and binary RepString(71) should return '1000111'

Explanation / Answer

def maxChar(string) :
list = sorted(string)
charac = list[len(list)-1]
for i in range(0,len(string)) :
if charac == string[i] :
print("The max char is '",charac,"' and occurs at position ", i,".")
break;

def binaryRepString(num) :
n = int(num)
if n == 0 :
return 0
binStr = ""
while n > 0 :
binStr = str((n%2))+binStr
n = n//2
return binStr


string = "abcdefaghaiayjkglb"
maxChar(string)
print(binaryRepString(0))