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 in Python by memyselfandpython
• 130 points
58 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 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
101 views
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
514 views
+1 vote
3 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]

Try using this question by list comprehension: a=[4,7,3,2,5,9] print([x for ...READ MORE

answered 2 days ago in Python by vinaykumar
• 160 points
627 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
128 views