
Patrick B. answered 05/23/21
Math and computer tutor/teacher
"""
Problem #1
Determining if the integer that is input
is an Even or odd integer
"""
#############################################
x = input("Please input the integer value :>")
if int(x)%2==0:
print(str(x) + " is even")
else:
print(str(x) + " is odd ")
"""
Problem #2 : determining if the string is or is not
a palindrome
"""
#############################################
str = input("Please input the string :>")
n = len(str)
iLeftIndexPos=0
iRightIndexPos=n-1
isPalindrome=True
while (iLeftIndexPos<iRightIndexPos):
if (str[iLeftIndexPos]!=str[iRightIndexPos]):
isPalindrome=False
break;
else:
iLeftIndexPos = iLeftIndexPos+1
iRightIndexPos = iRightIndexPos-1
outbuff = str + " is "
if isPalindrome==False:
outbuff = outbuff + "NOT "
outbuff = outbuff + " a palindrome. "
print(outbuff)
"""
Problem #3: Bubble Sort; Sorts a list of integer
values input by the user; ZER0 is used as the sentinel
#################################################
def Sort(sub_li):
l = len(sub_li)
for i in range(0, l):
for j in range(0, l-i-1):
if (int(sub_li[j]) > int(sub_li[j + 1])):
tempo = sub_li[j]
sub_li[j]= sub_li[j + 1]
sub_li[j + 1]= tempo
return sub_li
iNums = []
x=-1
while int(x)!=0:
x = input("Please input the integer value or ZER0 to quit :>")
if int(x)!=0:
iNums.append(x)
Sort(iNums)
print(iNums)
###########################
# Problem 4:Anagrams
###########################
def Sort(sub_li):
l = len(sub_li)
for i in range(0, l):
for j in range(0, l-i-1):
if (sub_li[j] > sub_li[j + 1]):
tempo = sub_li[j]
sub_li[j]= sub_li[j + 1]
sub_li[j + 1]= tempo
return sub_li
#################################################
def Str2CharList(str):
charListReturn = []
n = len(str)
for i in range(n):
charListReturn.append(str[i])
return(charListReturn)
#####################################
str1 = input("Please input the first string :>")
str2 = input("Please input the 2nd string :>")
n = len(str1)
if (n==len(str2)):
charList1 = Str2CharList(str1)
charList2 = Str2CharList(str2)
sortedStr1 = Sort(charList1)
sortedStr2 = Sort(charList2)
isAnagram=True
for i in range(n):
if (charList1[i]!=charList2[i]):
isAnagram=False
break
if isAnagram:
print(" they are anagrams ")
else:
print(" not anagrams")
else:
print(" not anagrams ")
#####################################
# Median of Three
################################
def MedianOfThree(x,y,z):
temp=0
if (x>y):
t=x
x=y
y=t
if (y>z):
t=y
y=z
z=t
if (x>y):
t=x
x=y
y=t
return y
#######################################
print(MedianOfThree(16,10,12))
Kobby E.
This is awesome! ;)05/23/21