INLAB 3
‘pneumonoultramicroscopicsilicovolcanoconiosis’
is the longest word in a dictionary with 45 letters. Given the value of ‘i'
and the value of ‘k' write an algorithm and the subsequent
Python code to output the five letters of the above longest string which
are in the positions that are the first five multiples of 2*i+k. If a
multiple is greater than the length of the string, then
continue the counting from the beginning of the string. For example, if
the value of i = 5 and k = 2 then the output letters are ‘r’, ‘c’, ‘n’, ‘e’,
and ‘i'. The longest string is stored in a variable named as 's' in the
precode, to be used for coding.
Input
Format
First
line contains the value of ‘i'
Second
line contains the value of ‘k'
Output
Format
Letters
in the position that are the first five multiples of 2*i + k, one
letter in one line
Input:
the
numbers i and k
Processing:
s
= 'pneumonoultramicroscopicsilicovolcanoconiosis'
multiple
= ((2*i) + k)
for
j in range(5):
multiple = multiple%45
multiple += ((2*i) + k)
Output:
The
letters at the positions of the five multiples in the string
Program:
s
= 'pneumonoultramicroscopicsilicovolcanoconiosis'
i
= int(input())
k
= int(input())
multiple
= ((2*i) + k)
for
j in range(5):
multiple = multiple%45
print(s[multiple-1])
multiple += ((2*i) + k)
Algorithm:
Step1.
Assign s as 'pneumonoultramicroscopicsilicovolcanoconiosis'
Step2.
Get the numbers i and k
Step3.
Let multiple be equal to sum of 2 multiplied by i and k
Step4.
Initialize j as 0 and repeat till j less than 5
Step4.1
assign multiple as the remainder obtained when multiple is divided by 45
Step4.2
display the letter in s at the position which is obtained when 1 is subtracted
from multiple
Step4.3
reassign multiple as the sum of multiple and the sum of 2 multiplied by i and k
Step5.
End
No comments:
Post a Comment