14,333,806 members
Rate this:
See more:
Write a program to get a string S, Type of conversion (1 - Convert to Lowercase, 2 - Convert to Uppercase) T, and integer P . Convert the case of the letters in the positions which are multiples of P.(1 based indexing).

Input Description:
Given a string S, Type of conversion T, and integer P

Output Description:
Convert the case of the letters and print the string

Sample Input :
ProFiLe
1
2

Sample Output :
Profile

What I have tried:

```text=input()
list1=list(text)
k=0
for i in range(0,len(list1)):
if(list1[i]=='p'or list1[i]=='P'):
k=i
k=k+1

for i in range(0,len(list1)):
if(i%k==0):

if(list1[i].islower()):
list1[i]=chr(ord(list1[i])-32)
if(list1[i].isupper()):
list1[i]=chr(ord(list1[i])+32)

ans="".join(list1)
print(ans)```
Posted
Updated 9-Oct-19 8:57am
v2

Rate this:

## Solution 1

I strongly suggest you re-read your homework question, paying close attention to this bit:
Quote:
Write a program to get a string S, Type of conversion (1 - Convert to Lowercase, 2 - Convert to Uppercase) T, and integer P .
That isn't what your code does, is it?
_gvsss 10-Oct-19 9:31am

thank you, after rectifying .I didn't get the later part
Convert the case of the letters in the positions which are multiples of P.(1 based indexing)
OriginalGriff 10-Oct-19 9:54am

What part of it don;t you get?
You have read P from the user, yes?
_gvsss 10-Oct-19 10:03am

yes
_gvsss 10-Oct-19 10:04am

p r o f i l e
1 2 3 4 5 6 7
p=2
multiples of 2 ?
OriginalGriff 10-Oct-19 10:09am

P=2 means you affect the second, fourth, sixth, ... characters.
Note: the question specifically wants 1 based indexing, and python arrays are zero based, so you will need to convert ...

Hint: Think about the first index value, and by how much you want to add each time round the loop ... do you have to look at every character at all?
_gvsss 10-Oct-19 10:10am

yeah got that just now
OriginalGriff 10-Oct-19 10:24am

Excellent!
It's a fine balance - trying to give you enough to help you work it out without giving it all away and you don't learn anything ... :laugh:
_gvsss 10-Oct-19 10:10am

I understood
I am sorry if this is a naive doubt I am a beginner for coding