Back to articles
Weekly Challenge: Counting the index

Weekly Challenge: Counting the index

via Dev.to PythonSimon Green

Weekly Challenge 365 Each week Mohammad S. Anwar sends out The Weekly Challenge , a chance for all of us to come up with solutions to two weekly tasks. My solutions are written in Python first, and then converted to Perl. Unless otherwise stated, Copilot (and other AI tools) have NOT been used to generate the solution. It's a great way for us all to practice some coding. Challenge , My solutions Task 1: Alphabet Index Digit Sum Task You are given a string $str consisting of lowercase English letters, and an integer $k . Write a script to convert a lowercase string into numbers using alphabet positions (a=1 … z=26), concatenate them to form an integer, then compute the sum of its digits repeatedly $k times, returning the final value. My solution This is a task of two parts. The first is to take the letters from input_string (as str is a reserved word in Python) to create a number. For this I use string.ascii_lowercase.index(letter)+1 to get each letter and append it to the digits variab

Continue reading on Dev.to Python

Opens in a new tab

Read Full Article
0 views

Related Articles