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
362 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
423 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 in Python by Niroj
• 68,780 points
1,047 views
0 votes
1 answer

How can I write code to find a palindrome in python without using string functions?

In Logic 1, try if i<int(length/2): instead of if i<int((length/2+1)): In ...READ MORE

answered Jan 16, 2019 in Python by charlie_brown
• 7,780 points
8,343 views
0 votes
1 answer

how do i print only the last two letters in a string using regular expression in python?

$ to match the end of the ...READ MORE

answered Mar 15, 2019 in Python by Waseem
• 4,540 points
152 views
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
833 views