Computer Science, asked by aalianasir3624, 1 month ago

Advit loves even numbers. Now, he want't to do a small experiment on even numbers, but decided to do it in a different way. He asks the user to enter a string and then prints all the characters at the even position in the given string, separated by a comma. *

Answers

Answered by Equestriadash
1

The following co‎des have been written using Python.

\tt s\ =\ in put("Enter\ a\ string:\ ")\\l\ =\ list()\\for\ i\ in\ range(0,\ len(s)\ +\ 1):\\{\ \ \ \ \ }if\ i\%2\ ==\ 0:\\{\ \ \ \ \ }{\ \ \ \ \ }l.append(s[i])\\print(l,\ "is\ the\ list\ of\ characters\ in\ the\ even\ position\ in\ the\\ string",\"'"\ +\  s\ +\ "'"\ +\ ".")

Once the string has been entered, we create a list to store the characters at the even index position from the string. We use a for loop, an iteration statement used to perform repeated checking. We give the range as (0, len(s) + 1), since index values start from 0 and end at the last length of the string. We check if the index is even/odd using a conditional statement. If it is even, we append [append is a list function used to add elements to a list, one by one.] it to the list that we created earlier. The final output is then printed.

Similar questions