I am trying to write a program in python for the occurrences of a character given the start and stop values of that string only using while

+1 vote
for eg:

string= PPYYTTHON

start and stop values are index 2 and 8

the for a character inputted by the user : Y

it should print 1
Nov 14, 2019 in Python by memyselfandpython
• 130 points
705 views

1 answer to this question.

0 votes

Here's the code:

check = input("Enter the character: ")
start = int(input("Start index: "))
stop = int(input("Stop index: "))
sentence = 'PPYYTTHON'
count = 0

for i in sentence[start+1: stop]:
    if i == check:
        count+=1

print (count)
answered Nov 15, 2019 by Rishi

Related Questions In Python

+1 vote
0 answers

Sum the values of column matching and not matching from a .txt file and write output to a two different files using Python

Name                                                    value DR_CNDAOFSZAPZP_GPFS_VOL.0 139264 DR_CNDAOFSZAPZP_GPFS_VOL.1 15657 DR_CNDAOFSZAPZP_GPFS_VOL.0 139264 DR_CNDAOFSZAPZP_GPFS_VOL.1 156579 DR_CNDAOFSZAPZP_GPFS_VOL.2 156579 DR_CNDAOFSZAPZP_GPFS_VOL.3 ...READ MORE

Nov 20, 2019 in Python by Sagar
• 130 points
676 views
0 votes
1 answer

Write code to create a list of word lengths for the words in original_str using the accumulation pattern and assign the answer to a variable num_words_list.

Hi,  num_words_list = len(original_str.split()) original_str.split() - split words in ...READ MORE

answered May 27, 2020 in Python by Niroj
• 82,820 points
1,754 views
0 votes
1 answer
0 votes
1 answer
+1 vote
1 answer

how do i get a optimal cutoff value(directly in the form of numeric) from roc curves?

The optimal CutOff value is the point ...READ MORE

answered Oct 17, 2019 in Python by Saira
1,666 views