Please answer the following questions in basic python code. Please use comments
ID: 3743816 • Letter: P
Question
Please answer the following questions in basic python code. Please use comments where necessary.
6. input: a string with character in it, a string with numbers in it
output: go through the two strings together. At index i, if the number in str2 is even, put the letter in str1 into evenStr
if the number is odd, put the letter into oddStr. Return the even/odd strings
Sample: "helloworld" "2435232399"
gives evenStr="heoo" oddStr="llwrld"
'''
#def two_strings(str1,str2)
7.
The number 6 is a truly great number. Given two int values, a and b, return True
if either one is 6. Or if their sum or difference is 6.
Note: the function abs(num) computes the absolute value of a number.
love6(6, 4) returns True
love6(4, 5) returns False
love6(1, 5) returns True
'''
#def love6(a,b):
Explanation / Answer
1) def two_strings(str1, str2): evenStr = '' oddStr = '' for i in range(len(str1)): if (ord(str2[i]) - ord('0')) % 2 == 0: evenStr += str1[i] else: oddStr += str1[i] return evenStr, oddStr print(two_strings('helloworld', '2435232399')) 2) def love6(a, b): return a == 6 or b == 6 or (a+b) == 6 or a-b == 6 or b-a == 6 print(love6(6, 4)) print(love6(4, 5)) print(love6(1, 5))