How do I count the number of times the string (y/n) outputs

0 votes
yes = "y" or "Y"
no = "n" or "N"
quest1 = input("solved problem 1: " + yes + "/" + no + " ")
quest2 = input("solved problem 2: " + yes + "/" + no+ " ")
 
if quest1 or quest2 == no:
  print("Please answer 'y' or 'n' for :")
elif quest1 or quest2 == yes:
  print("You should not come to class.")
  exit()

quest3 = input("solved part 1: " + yes + "/" + no + " ")
quest4 = input("solved part 2: " + yes + "/" + no+ " ")
quest5 = input("solved part 3: " + yes + "/" + no + " ")
quest6 = input("solved part 4: " + yes + "/" + no+ " ")


#how can I count these y/n into the number of times of occurrences as output? so I can use if statements to print as per the number of times yes and no is answered.

Oct 13 in Python by Reshma
• 120 points

edited Oct 13 by Gitika 107 views

1 answer to this question.

0 votes

Hi, @Reshma,

You can go through this as an example:

def count(a, b, m, n): 

  

    # If both first and second string 

    # is empty, or if second string 

    # is empty, return 1 

    if ((m == 0 and n == 0) or n == 0): 

        return 1

  

    # If only first string is empty 

    # and second string is not empty,

    # return 0 

    if (m == 0):

        return 0

  

    # If last characters are same 

    # Recur for remaining strings by 

    # 1. considering last characters 

    #    of both strings 

    # 2. ignoring last character 

    #    of first string 

    if (a[m - 1] == b[n - 1]): 

        return (count(a, b, m - 1, n - 1) + 

                count(a, b, m - 1, n)) 

    else:

          

      

      return count(a, b, m - 1, n) 

print(count(a, b, len(a),len(b)))

Output:

4
answered Oct 13 by Lisa sanyal

Related Questions In Python

+1 vote
1 answer
0 votes
1 answer

How do I get the number of elements in a list?

Hello, The len() function can be used with several different ...READ MORE

answered Nov 18 in Python by Niroj
• 78,120 points
13 views
0 votes
1 answer

In NumPy how do I get the maximum of subsets? Python

You can use np.maximum.reduceat: >>> _, idx = np.unique(g, ...READ MORE

answered Nov 9, 2018 in Python by Nymeria
• 3,520 points
341 views
0 votes
1 answer

How can I get the count of a list in Python?

len() >>> mylist=[] >>> print len(mylist) 0 READ MORE

answered Dec 12, 2018 in Python by charlie_brown
• 7,780 points
276 views
+2 votes
1 answer

How can I record the X,Y limits of a displayed X,Y plot using the matplotlib show() module?

A couple hours after posting this question ...READ MORE

answered Dec 27, 2018 in Python by anonymous
162 views
0 votes
1 answer

how do I check the length of an array in a python program?

lets say we have a list mylist = ...READ MORE

answered Mar 12, 2019 in Python by Mohammad
• 3,210 points
252 views
0 votes
1 answer