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:


start and stop values are index 2 and 8

the for a character inputted by the user : Y

it should print 1
Nov 14 in Python by memyselfandpython
• 130 points

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:

print (count)
answered Nov 15 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 in Python by Sagar
• 130 points
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How can I write a program to add two numbers using functions in python?

def add(a,b):      return a + b #when i call ...READ MORE

answered May 20 in Python by Mohammad
• 3,170 points
0 votes
2 answers

Write a for loop that prints all elements of a list and their position in the list. a = [4,7,3,2,5,9]

a = [4,7,3,2,5,9] b = enumerate(a) for i in ...READ MORE

answered Jul 15 in Python by Kei Tee

edited Jul 22 by Kalgi 580 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 in Python by Saira