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, 2020 in Python by Reshma
• 120 points

edited Oct 13, 2020 by Gitika 1,342 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, 2020 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, 2020 in Python by Niroj
• 82,880 points
602 views
0 votes
1 answer

How do I get the number of elements in a list

items = [] items.append("apple") items.append("orange") items.append("banana") len(items) #use the ...READ MORE

answered Feb 15, 2022 in Python by Dev
• 6,000 points
606 views
0 votes
1 answer

How do I get the number of elements in a list

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

answered Feb 15, 2022 in Python by CoolCoder
• 4,420 points
570 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,560 points
1,515 views
0 votes
2 answers

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

n=[1,2,3,4,5,6,7,8,9] print(len(n)) =9 READ MORE

answered Dec 10, 2020 in Python by anonymous
1,417 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
1,100 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP