Answer to Question #258976 in Python for omkar

Question #258976

choose two characters a and b in the string. swap a with b if and only if the sum of ascii values a and b are odd


1
Expert's answer
2021-10-30T10:37:40-0400
string = 'I am a boy'
a = string[0]
b = string[1]
Total_sum = 0
for i in [a,b]:
  Total_sum = sum(map(ord, i))
if Total_sum % 2 != 0:
  string1 = string.replace(string[0], string[2])
  print(string1)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog