1

Ahmed is sending the final list of the names of the Computer Olympiad entrants to the results review committee so that the committee can print the final entry cards, but because there was no specific format for registering the names during the exam, the participants were nominated as standard. They did not write themselves. In addition, it is written in the continuation of each language name with which it has participated in the competitions, and at the beginning of each name, the gender of the people is specified. The standard form of nouns is such that the first letter of the noun is uppercase and the rest of the letters of the noun are lowercase. Write a program that reads the number, name, gender, and language of the entrants from the input, segregates the names based on gender, standardizes them, and writes in front of each name the language with which it competed. (In the output, first the gender of the woman and then the gender of the man should be printed. Names in each gender should be printed in the English alphabet.)

 Sample input:
     m.hosSein.python
     f.miNa.C
     m.aHMad.C++
     f.Sara.java
    Sample output:
    f Mina C
    f Sara java
    m Ahmad C++
    m Hossein python

How do I correct this code؟How to correct uppercase and lowercase letters؟

def Olampiad(n):
    my_list = []
    for i in range(0, n):
        s = input()
        s = s.lower()
        my_list.append(s.strip().split('.'))
    my_list = sorted(my_list)
    return my_list


n = int(input(''))

for char in Olampiad(n):

    if char[0] == 'f':
        if char[2] == 'c' or char[2] == 'c++' or char[2] == 'c#' or char[2] == 'java':
            print(char[0], char[1].capitalize(), char[2])
        else:
            print(char[0], char[1].capitalize(), char[2])

    if char[0] == 'm':
        if char[2] == 'c' or char[2] == 'c++' or char[2] == 'c#' or char[2] == 'java':
            print(char[0], char[1].capitalize(), char[2])
        else:
            print(char[0], char[1].capitalize(), char[2])
rani
  • 29
  • 4
  • 1
    It can be any name for example char – rani Sep 05 '20 at 21:06
  • _Note: If you intend to use a dictionary to solve your problems, note that the dictionary does not maintain order._ - it does in python 3.7+ - insertion order - they might want to adjust the task description – Patrick Artner Sep 05 '20 at 21:08

2 Answers2

0

You do not sort by the gender nor do you sort by the name alphabetically afterwards as tasked. Your code prints immediately.

You need to

  • get all the data in
  • split and sort it
  • fix the spelling

and then print in the correct order:

print( *[f"{a} {b.capitalize()} {c}" 
            for a,b,c in sorted([input().strip().split(".") 
                                for _ in range(int(input()))],
                                key=lambda x:(x[0],x[1].lower()))], 
        sep="\n")

with an input of

4
m.hosSein.python
f.miNa.C
m.aHMad.C++
f.Sara.jav

you get an output of

f Mina C
f Sara jav
m Ahmad C++
m Hossein python 

Readup:

Patrick Artner
  • 50,409
  • 9
  • 43
  • 69
0

your code should be :

x = int(input())
z = list()
for i in range(x):
    y = input()
    y = y.split('.')
    z.append(y)
for ii in range(len(z)):
    z[ii][1] = z[ii][1].lower()
    z[ii][1] = z[ii][1].capitalize()
    z[ii] = tuple(z[ii])
z.sort(key = lambda x: x[1])
z.sort()
for iii in range(len(z)):
    print(z[iii][0],z[iii][1],z[iii][2])