The Joy of Computing with Python Unproctored exam (8-9PM) Review |Question paper and answer given

Swayam portal logo


     Basically the evening session is lighter tough for me. I solved in half an hour. If you did not see the morning session review. First read that and come back for to read this article.

     *Also Read -> Joc morning session review (question and answer included) 

     *Also Read -> Joc Proctored exam (Dec 19, 2020) Review

     Now we are going to see the question and answer(my solution) for evening session. This blog will help for upcoming batches, to know how was the unproctored exam.  This is open resource exam and 1 hour duration. 

     Note:

     In future batches they may ask more questions or less questions but any number of questions they ask that can be solved within 1hour. Because they fix the questions in that way. For this session (Dec 2020) morning 8-9PM Unproctored exam, they asked only one question to solve.

     Note:

     This is for only educational purpose. The question and answer for the exam  in this blog is posted  only after the exam is completed i.e. after 9 pm for morning session.

Question paper and answer for unproctored exam 8-9PM

Programming exam 2: Word count

You are given some words. Some of them may repeat. For each word, output its number of occurrences. The output order should correspond with the input order of appearance of the word. See the sample input/output for clarification.


Note: 
All the words are composed of lowercase English letters only.


Input Format

It should contain all the words separated by space.


Output Format

Output the number of distinct words from the input  
Output the number of occurrences for each distinct word according to their appearance in the input.
Both the outputs should be separated by space.

Sample Input

bcdef abcdefg bcde bcdef

Sample Output

3 211

Explanation

There are distinct words. Here, "bcdef" appears twice in the input at the first and last positions. The other words appear once each. The order of the first appearances are "bcdef", "abcdefg" and "bcde" which corresponds to the output.


Answer (my own solution) :
n=list(map(str,input().split()))
a=set(n)   
num=len(a)     #finding the number of distinct words
d={}
for i in a:
  count=0
  for j in range(len(n)):
    if i==n[j]:
      count+=1
  d[i]=count     #finding the count of repeated words
b={}
for i in n:
  for j in d.keys():
    if i==j:
      b[i]=d[j]      #arranging the count of words according to the given order in input
f=""
for i in b.values():
  i=str(i)
  f=f+i       #joining the count together
print(num,f,end="")



     This answer passed in both public and private test cases.  There are many ways to solve this problem not only this.


     
     *Also Read  -> Joc Proctored exam (Dec 19, 2020) Review
-----------------------------------------------------------------------------------------------------------------------------
Content Last Updated on 5th August 2021, 3:00 PM IST

Post a Comment

Previous Post Next Post