Answer to Question #290252 in Python for Bubby

Question #290252

SPECIAL NUMBERS


you only like numbers that start with an odd digit. anil gives you space-separated integers as input . your task is left-rotate every number in the list (if required) so that can be liked by you.


NOTE:


if there is no odd digit in the number , do not rotate it.

if a number starts with an odd digit , do not rotate it


INPUT :


The first line of the input contains space-separated integers


OUTPUT:


The out should be a single line containing space separated integers with odd digit as first digit for each number.


EXPLANATION:


in the example, input is 21, 503, 256, 550, 86, 979, 281

Rotate all the words to the left so that each number starts with an odd digit .


Input1: 21 503 256 550 86 979 281

Output 1: 12 503 562 550 86 979 128


Input 2: 2001 463 6219 669 473 1006 77734 110 20511

Output 2: 1200 346 1962 966 734 1006 77734 110 511120


1
Expert's answer
2022-01-24T11:09:09-0500
def rotate(n_str):


	for i in range(len(n_str)):
		if int(n_str[i]) % 2 != 0:
			return n_str[i:] + n_str[:i]
	return n_str




nums = [rotate(i) for i in input().split()]
print(*nums)

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
APPROVED BY CLIENTS