WEEK 1 to 8 ASSIGNMENT SOLUTION of Programming, data structures and algorithms using Python Nptel : TCPTUTOR

103
6883



For exam on Sunday, 7th October, 2018 you may check this post for preparation https://rebrand.ly/learnpythontcp for the course Programming, data structures and algorithms using Python of Nptel.

Solution for Programming, data structures and algorithms using Python of Nptel

Week 8 Programming assignment link https://rebrand.ly/pythonwk8asgn (Due on 2018-10-04, 23:59 IST).

Week 7 quiz solution (Due date for this assignment: 2018-09-27, 23:59 IST. )(kindly visit again before 23:59 IST as answer may get updated if found incorrect) :

Q.1 : fjadcbeghi

Q.2 : 1+self.next.length()

Q.3 : c) The length of the longest path from root to leaf in mytree.

Q.4 : d

Week 6 quiz solution (Due date for this assignment: 2018-09-20, 23:59 IST. ) :

Q.1 : b) 

Q.2 : a) This is true for any u and v.

Q.3 : [98,67,89,38,42,54,89,17,25]

Q.4 : [98,97,89,38,67,54,89,17,25,42]

Week 5 Programming assignment link https://rebrand.ly/pythonwk5asgn (Due on 2018-09-16, 23:59 IST).

Week 4 Programming assignment link https://rebrand.ly/pythonwk4assign (Due on 2018-09-13, 23:59 IST).

Week 4 quiz solution (Due date for this assignment: 2018-09-13, 23:59 IST. ) :

Q.1 : [15, 81, 17, 23, 13]

Q.2 : [(0, 0), (1, 2), (2, 1), (3, 0)]

Q.3 : b)

Q.4 : a) d[[1,2]] = 5



Week 3 Programming assignment link https://rebrand.ly/pythonwk3asgn (Due on 2018-09-06, 23:59 IST).

Week 2 quiz solution (Due on 2018-09-06, 23:59 IST):

Q.1 : 6

Q.2 : d) x[1] == 40, y[1] == 40, w[0] == 4, u[0] == 50

Q.3 : “olleh”

Q.4 : [31,24,75]

Week 1 and 2 assignment solution https://rebrand.ly/pythonweek1and2 . Last date of submission of week 1 assignment is 23rd August, 2018 before 23:59 IST and Last date of submission of week 2 assignment is 6th September, 2018 before 23:59 IST.



103 COMMENTS

    • Week 4 assignment is already updated. Kindly click on gdrive link, you will get a .txt file with code, just copy and paste that code on nptel site.

      • Solution for this: week 5 programming assignment.. due date is today.. please send the code by today evening… please help..

        ________________________________________
        The library at the Hogwarts School of Witchcraft and Wizardry has computerized its book issuing process. The relevant information is provided as text from standard input in three parts: information about books, information about borrowers and information about checkouts. Each part has a specific line format, described below.
        Information about books
        Line format: Accession Number~Title
        Information about borrowers
        Line format: Username~Full Name
        Information about checkouts
        Line format: Username~Accession Number~Due Date
        Note: Due Date is in YYYY-MM-DD format.
        You may assume that the data is internally consistent. For every checkout, there is a corresponding username and accession number in the input data, and no book is simultaneously checked out by two people.
        Each section of the input starts with a line containing a single keyword. The first section begins with a line containing Books. The second section begins with a line containing Borrowers. The third section begins with a line containing Checkouts. The end of the input is marked by a line containing EndOfInput.
        Write a Python program to read the data as described above and print out details about books that have been checked out. Each line should describe to one currently issued book in the following format:
        Due Date~Full Name~Accession Number~Title
        Your output should be sorted in increasing order of due date. For books due on the same date, sort in increasing order of full name.
        sample input and its corresponding output.
        Sample Input
        Books
        APM-001~Advanced Potion-Making
        GWG-001~Gadding With Ghouls
        APM-002~Advanced Potion-Making
        DMT-001~Defensive Magical Theory
        DMT-003~Defensive Magical Theory
        GWG-002~Gadding With Ghouls
        DMT-002~Defensive Magical Theory
        Borrowers
        SLY2301~Hannah Abbott
        SLY2302~Euan Abercrombie
        SLY2303~Stewart Ackerley
        SLY2304~Bertram Aubrey
        SLY2305~Avery
        SLY2306~Malcolm Baddock
        SLY2307~Marcus Belby
        SLY2308~Katie Bell
        SLY2309~Sirius Orion Black
        Checkouts
        SLY2304~DMT-002~2019-03-27
        SLY2301~GWG-001~2019-03-27
        SLY2308~APM-002~2019-03-14
        SLY2303~DMT-001~2019-04-03
        SLY2301~GWG-002~2019-04-03
        EndOfInput
        Sample Output
        2019-03-14~Katie Bell~APM-002~Advanced Potion-Making
        2019-03-27~Bertram Aubrey~DMT-002~Defensive Magical Theory
        2019-03-27~Hannah Abbott~GWG-001~Gadding With Ghouls
        2019-04-03~Hannah Abbott~GWG-002~Gadding With Ghouls
        2019-04-03~Stewart Ackerley~DMT-001~Defensive Magical Theory
        Top of Form
        Select the Language for this assignment.

        1

        You may submit any number of times before the due date. The final submission will be considered for grading.
        Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program, your assignment will not be graded and you will not see your score after the deadline.
        Reset Submit Compile & Run Save as Draft
        Bottom of Form

        Sample Test Cases
        Input Output
        Test Case 1 Books
        APM-001~Advanced Potion-Making
        GWG-001~Gadding With Ghouls
        APM-002~Advanced Potion-Making
        DMT-001~Defensive Magical Theory
        DMT-003~Defensive Magical Theory
        GWG-002~Gadding With Ghouls
        DMT-002~Defensive Magical Theory
        Borrowers
        SLY2301~Hannah Abbott
        SLY2302~Euan Abercrombie
        SLY2303~Stewart Ackerley
        SLY2304~Bertram Aubrey
        SLY2305~Avery
        SLY2306~Malcolm Baddock
        SLY2307~Marcus Belby
        SLY2308~Katie Bell
        SLY2309~Sirius Orion Black
        Checkouts
        SLY2304~DMT-002~2019-03-27
        SLY2301~GWG-001~2019-03-27
        SLY2308~APM-002~2019-03-14
        SLY2303~DMT-001~2019-04-03
        SLY2301~GWG-002~2019-04-03
        EndOfInput
        2019-03-14~Katie Bell~APM-002~Advanced Potion-Making
        2019-03-27~Bertram Aubrey~DMT-002~Defensive Magical Theory
        2019-03-27~Hannah Abbott~GWG-001~Gadding With Ghouls
        2019-04-03~Hannah Abbott~GWG-002~Gadding With Ghouls
        2019-04-03~Stewart Ackerley~DMT-001~Defensive Magical Theory

        Test Case 2 Books
        GTF-001~A Beginner’s Guide to Transfiguration
        GTF-002~A Beginner’s Guide to Transfiguration
        GTF-003~A Beginner’s Guide to Transfiguration
        WET-001~Great Wizarding Events of the Twentieth Century
        WET-002~Great Wizarding Events of the Twentieth Century
        WTC-001~Great Wizards of the Twentieth Century
        WTC-002~Great Wizards of the Twentieth Century
        WTC-003~Great Wizards of the Twentieth Century
        WTC-004~Great Wizards of the Twentieth Century
        IBI-001~Invisible Book of Invisibility
        IBI-002~Invisible Book of Invisibility
        JFJ-001~Jinxes for the Jinxed
        JFJ-002~Jinxes for the Jinxed
        LDM-001~Men Who Love Dragons Too Much
        LDM-002~Men Who Love Dragons Too Much
        LDM-003~Men Who Love Dragons Too Much
        NTN-001~New Theory of Numerology
        MFM-001~One Minute Feasts – It’s Magic!
        PYN-001~Powers You Never Knew You Had and What To Do With Them Now You’ve Wised Up
        PYN-002~Powers You Never Knew You Had and What To Do With Them Now You’ve Wised Up
        PYN-003~Powers You Never Knew You Had and What To Do With Them Now You’ve Wised Up
        PDM-001~Practical Defensive Magic and Its Use Against the Dark Arts
        PDM-002~Practical Defensive Magic and Its Use Against the Dark Arts
        PDM-003~Practical Defensive Magic and Its Use Against the Dark Arts
        PDM-004~Practical Defensive Magic and Its Use Against the Dark Arts
        QAQ-001~Quintessence: A Quest
        QAQ-002~Quintessence: A Quest
        STS-001~Saucy Tricks for Tricky Sorts
        STS-002~Saucy Tricks for Tricky Sorts
        STS-003~Saucy Tricks for Tricky Sorts
        STS-004~Saucy Tricks for Tricky Sorts
        Borrowers
        SLY2301~Hannah Abbott
        SLY2307~Marcus Belby
        SLY2311~Susan Bones
        SLY2313~Eleanor Branstone
        SLY2319~Eddie Carmichael
        GRF3703~Dennis Creevey
        GRF3708~J. Dorny
        GRF3715~Basil Fronsac
        RAV4308~Olive Hornby
        RAV4309~Angelina Johnson
        RAV5902~Isobel MacDougal
        RAV5905~Laura Madley
        RAV5906~Draco Malfoy
        RAV5907~Natalie McDonald
        GRF9104~Lily Moon
        GRF9107~Garrick Ollivander
        Checkouts
        RAV5906~GTF-001~2019-03-22
        GRF3708~GTF-002~2019-03-26
        SLY2307~GTF-003~2019-03-01
        GRF3708~WET-001~2019-03-06
        SLY2301~WET-002~2019-03-23
        SLY2307~WTC-001~2019-02-26
        SLY2311~WTC-002~2019-03-12
        SLY2313~WTC-003~2019-03-06
        SLY2301~WTC-004~2019-03-12
        RAV5906~IBI-001~2019-03-12
        SLY2307~IBI-002~2019-03-23
        GRF3715~JFJ-001~2019-03-23
        RAV5905~JFJ-002~2019-03-16
        SLY2311~LDM-001~2019-02-26
        RAV4308~LDM-002~2019-03-20
        SLY2307~LDM-003~2019-03-22
        GRF3703~NTN-001~2019-03-09
        RAV4308~MFM-001~2019-03-07
        SLY2311~PYN-001~2019-03-03
        RAV5902~PYN-002~2019-03-02
        GRF9104~PYN-003~2019-03-16
        GRF3708~PDM-001~2019-03-13
        RAV5907~PDM-002~2019-03-26
        SLY2307~PDM-003~2019-02-26
        SLY2313~PDM-004~2019-03-01
        RAV4309~QAQ-001~2019-03-14
        RAV5907~QAQ-002~2019-03-17
        RAV5905~STS-001~2019-03-12
        SLY2319~STS-002~2019-03-11
        GRF3703~STS-003~2019-03-19
        RAV5907~STS-004~2019-03-17
        EndOfInput
        2019-02-26~Marcus Belby~PDM-003~Practical Defensive Magic and Its Use Against the Dark Arts
        2019-02-26~Marcus Belby~WTC-001~Great Wizards of the Twentieth Century
        2019-02-26~Susan Bones~LDM-001~Men Who Love Dragons Too Much
        2019-03-01~Eleanor Branstone~PDM-004~Practical Defensive Magic and Its Use Against the Dark Arts
        2019-03-01~Marcus Belby~GTF-003~A Beginner’s Guide to Transfiguration
        2019-03-02~Isobel MacDougal~PYN-002~Powers You Never Knew You Had and What To Do With Them Now You’ve Wised Up
        2019-03-03~Susan Bones~PYN-001~Powers You Never Knew You Had and What To Do With Them Now You’ve Wised Up
        2019-03-06~Eleanor Branstone~WTC-003~Great Wizards of the Twentieth Century
        2019-03-06~J. Dorny~WET-001~Great Wizarding Events of the Twentieth Century
        2019-03-07~Olive Hornby~MFM-001~One Minute Feasts – It’s Magic!
        2019-03-09~Dennis Creevey~NTN-001~New Theory of Numerology
        2019-03-11~Eddie Carmichael~STS-002~Saucy Tricks for Tricky Sorts
        2019-03-12~Draco Malfoy~IBI-001~Invisible Book of Invisibility
        2019-03-12~Hannah Abbott~WTC-004~Great Wizards of the Twentieth Century
        2019-03-12~Laura Madley~STS-001~Saucy Tricks for Tricky Sorts
        2019-03-12~Susan Bones~WTC-002~Great Wizards of the Twentieth Century
        2019-03-13~J. Dorny~PDM-001~Practical Defensive Magic and Its Use Against the Dark Arts
        2019-03-14~Angelina Johnson~QAQ-001~Quintessence: A Quest
        2019-03-16~Laura Madley~JFJ-002~Jinxes for the Jinxed
        2019-03-16~Lily Moon~PYN-003~Powers You Never Knew You Had and What To Do With Them Now You’ve Wised Up
        2019-03-17~Natalie McDonald~QAQ-002~Quintessence: A Quest
        2019-03-17~Natalie McDonald~STS-004~Saucy Tricks for Tricky Sorts
        2019-03-19~Dennis Creevey~STS-003~Saucy Tricks for Tricky Sorts
        2019-03-20~Olive Hornby~LDM-002~Men Who Love Dragons Too Much
        2019-03-22~Draco Malfoy~GTF-001~A Beginner’s Guide to Transfiguration
        2019-03-22~Marcus Belby~LDM-003~Men Who Love Dragons Too Much
        2019-03-23~Basil Fronsac~JFJ-001~Jinxes for the Jinxed
        2019-03-23~Hannah Abbott~WET-002~Great Wizarding Events of the Twentieth Century
        2019-03-23~Marcus Belby~IBI-002~Invisible Book of Invisibility
        2019-03-26~J. Dorny~GTF-002~A Beginner’s Guide to Transfiguration
        2019-03-26~Natalie McDonald~PDM-002~Practical Defensive Magic and Its Use Against the Dark Arts

  1. I’m very much thank full to you.
    This site is very well organised and frequently updated.
    please provide the answers for 7th week quiz (PDSA using python NPTEL) as well.

  2. i appreciate TCP tutor for their efforts. the solutions are really useful to the beginners. providing a explanation to these solutions will be very useful to the newbies.

  3. please provide the answer of nptel week 5 programming assignment 2019 ….I will be very thankful to you if u give solution ..

    This is a practice programming assignment. It will not be counted towards your marks in the course.
    For this assignment, you have to write a complete Python program.
    You may define additional auxiliary functions as needed.
    In all cases you may assume that the input to your program has the expected format, so your program does not have to check for malformed inputs.
    There are some public test cases and some (hidden) private test cases.
    “Compile and run” will evaluate your submission against the public test cases.
    “Submit” will evaluate your submission against the hidden private test cases and report a score on 100.
    Ignore warnings about “Presentation errors”.
    Note: Normally, you will not get any feedback on which private test cases pass or fail. Since this is a practice assignment, the private test cases are exactly the same as the public ones.

    The academic office at the Hogwarts School of Witchcraft and Wizardry has compiled data about students’ grades. The data is provided as text from standard input in three parts: information about courses, information about students and information about grades. Each part has a specific line format, described below..
    Information about courses
    Line format: Course Code~Course Name~Semester~Year~Instructor
    Information about students
    Line format: Roll Number~Full Name
    Information about grades
    Line format: Course Code~Semester~Year~Roll Number~Grade
    The possible grades are A, AB, B, BC, C, CD, D with corresponding grade points 10, 9, 8, 7, 6, 5 and 4. The grade point average of a student is the sum of his/her grade points divided by the number of courses. For instance, if a student has taken two courses with grades A and C, the grade point average is 8 = (10+6)÷2. If a student has not completed any courses, the grade point average is defined to be 0.
    You may assume that the data is internally consistent. For every grade, there is a corresponding course code and roll number in the input data.
    Each section of the input starts with a line containing a single keyword. The first section begins with a line containing Courses. The second section begins with a line containing Students. The third section begins with a line containing Grades. The end of the input is marked by a line containing EndOfInput.
    Write a Python program to read the data as described above and print out a line listing the grade point average for each student in the following format:
    Roll Number~Full Name~Grade Point Average
    Your output should be sorted by Roll Number. The grade point average should be rounded off to 2 digits after the decimal point. Use the built-in function round().
    Here is a sample input and its corresponding output.
    Sample Input
    Courses
    TRAN~Transfiguration~1~2011-2012~Minerva McGonagall
    CHAR~Charms~1~2011-2012~Filius Flitwick
    Students
    SLY2301~Hannah Abbott
    SLY2302~Euan Abercrombie
    SLY2303~Stewart Ackerley
    SLY2304~Bertram Aubrey
    SLY2305~Avery
    SLY2306~Malcolm Baddock
    SLY2307~Marcus Belby
    SLY2308~Katie Bell
    SLY2309~Sirius Orion Black
    Grades
    TRAN~1~2011-2012~SLY2301~AB
    TRAN~1~2011-2012~SLY2302~B
    TRAN~1~2011-2012~SLY2303~B
    TRAN~1~2011-2012~SLY2305~A
    TRAN~1~2011-2012~SLY2306~BC
    TRAN~1~2011-2012~SLY2308~A
    TRAN~1~2011-2012~SLY2309~AB
    CHAR~1~2011-2012~SLY2301~A
    CHAR~1~2011-2012~SLY2302~BC
    CHAR~1~2011-2012~SLY2303~B
    CHAR~1~2011-2012~SLY2305~BC
    CHAR~1~2011-2012~SLY2306~C
    CHAR~1~2011-2012~SLY2307~B
    CHAR~1~2011-2012~SLY2308~AB
    EndOfInput
    Sample Input
    SLY2301~Hannah Abbott~9.5
    SLY2302~Euan Abercrombie~7.5
    SLY2303~Stewart Ackerley~8.0
    SLY2304~Bertram Aubrey~0
    SLY2305~Avery~8.5
    SLY2306~Malcolm Baddock~6.5
    SLY2307~Marcus Belby~8.0
    SLY2308~Katie Bell~9.5
    SLY2309~Sirius Orion Black~9.0

  4. sorry answer of that question is already
    please provide the answer of the following question
    For this assignment, you have to write a complete Python program.
    You may define additional auxiliary functions as needed.
    In all cases you may assume that the input to your program has the expected format, so your program does not have to check for malformed inputs.
    There are 2 public test cases and 6 (hidden) private test cases.
    “Compile and run” will evaluate your submission against the public test cases.
    “Submit” will evaluate your submission against the hidden private test cases and report a score on 100.
    Ignore warnings about “Presentation errors”.

    The library at the Hogwarts School of Witchcraft and Wizardry has computerized its book issuing process. The relevant information is provided as text from standard input in three parts: information about books, information about borrowers and information about checkouts. Each part has a specific line format, described below.
    Information about books
    Line format: Accession Number~Title
    Information about borrowers
    Line format: Username~Full Name
    Information about checkouts
    Line format: Username~Accession Number~Due Date
    Note: Due Date is in YYYY-MM-DD format.
    You may assume that the data is internally consistent. For every checkout, there is a corresponding username and accession number in the input data, and no book is simultaneously checked out by two people.
    Each section of the input starts with a line containing a single keyword. The first section begins with a line containing Books. The second section begins with a line containing Borrowers. The third section begins with a line containing Checkouts. The end of the input is marked by a line containing EndOfInput.
    Write a Python program to read the data as described above and print out details about books that have been checked out. Each line should describe to one currently issued book in the following format:
    Due Date~Full Name~Accession Number~Title
    Your output should be sorted in increasing order of due date. For books due on the same date, sort in increasing order of full name.
    Here is a sample input and its corresponding output.
    Sample Input
    Books
    APM-001~Advanced Potion-Making
    GWG-001~Gadding With Ghouls
    APM-002~Advanced Potion-Making
    DMT-001~Defensive Magical Theory
    DMT-003~Defensive Magical Theory
    GWG-002~Gadding With Ghouls
    DMT-002~Defensive Magical Theory
    Borrowers
    SLY2301~Hannah Abbott
    SLY2302~Euan Abercrombie
    SLY2303~Stewart Ackerley
    SLY2304~Bertram Aubrey
    SLY2305~Avery
    SLY2306~Malcolm Baddock
    SLY2307~Marcus Belby
    SLY2308~Katie Bell
    SLY2309~Sirius Orion Black
    Checkouts
    SLY2304~DMT-002~2019-03-27
    SLY2301~GWG-001~2019-03-27
    SLY2308~APM-002~2019-03-14
    SLY2303~DMT-001~2019-04-03
    SLY2301~GWG-002~2019-04-03
    EndOfInput
    Sample Output
    2019-03-14~Katie Bell~APM-002~Advanced Potion-Making
    2019-03-27~Bertram Aubrey~DMT-002~Defensive Magical Theory
    2019-03-27~Hannah Abbott~GWG-001~Gadding With Ghouls
    2019-04-03~Hannah Abbott~GWG-002~Gadding With Ghouls
    2019-04-03~Stewart Ackerley~DMT-001~Defensive Magical Theory

    • I too want the solution for this.. if u find out.. please please share with me.. it’ll be very useful.. thanks in advance..

    • Answer for the week 5 programming assignment:
      copy as it is and paste it…. 6/6 test cases passed…

      def borrowers_input(b):
      x=input()
      while x!=’Checkouts’:
      x=x.split(‘~’)
      b.append(x)
      x=input()

      def checkouts_input(c):
      x=input()
      while x!=’EndOfInput’:
      x=x.split(‘~’)
      c.append(x)
      x=input()

      def output():
      global books,borrower,checkout
      date=[]
      uname=[]
      name=[]
      Anum=[]
      title=[]
      for i in range(0,len(checkout)):
      date.append(checkout[i][2])

      for i in range(0,len(checkout)):
      uname.append(checkout[i][0])

      for i in range(0,len(uname)):
      for j in range(0,len(borrower)):
      if(uname[i] == borrower[j][0]):
      name.append(borrower[j][1])

      for i in range(0,len(checkout)):
      Anum.append(checkout[i][1])

      for i in range(0,len(Anum)):
      for j in range(0,len(books)):
      if(Anum[i] == books[j][0]):
      title.append(books[j][1])

      final=[]
      for i in range(0,len(checkout)):
      final.append(date[i]+’~’+name[i]+’~’+Anum[i]+’~’+title[i])
      final.sort()
      for i in range(0,len(final)):
      print(final[i])

      books=[]
      borrower=[]
      checkout=[]
      x=input()
      x=input()
      while x!=’Borrowers’:
      x=x.split(‘~’)
      books.append(x)
      x=input()
      borrowers_input(borrower)
      borrower.sort()
      checkouts_input(checkout)
      output()

      • it is not getting run, both test cases failed,the code is written plane in this comment, but in python therre must be intended..so theres’s error in this…..So, can you put that run code agaian please.

      • could you kindly send me the code for the first one that is the admin office problem where grade calculations have to be done plz

      • madam aishwarya kindly send me the code for the practice programming assignment, my internals are already low, please help me.

        • def borrowers_input(b):
          x=input()
          while x!=’Checkouts’:
          x=x.split(‘~’)
          b.append(x)
          x=input()

          def checkouts_input(c):
          x=input()
          while x!=’EndOfInput’:
          x=x.split(‘~’)
          c.append(x)
          x=input()

          def output():
          global books,borrower,checkout
          date=[]
          uname=[]
          name=[]
          Anum=[]
          title=[]
          for i in range(0,len(checkout)):
          date.append(checkout[i][2])

          for i in range(0,len(checkout)):
          uname.append(checkout[i][0])

          for i in range(0,len(uname)):
          for j in range(0,len(borrower)):
          if(uname[i] == borrower[j][0]):
          name.append(borrower[j][1])

          for i in range(0,len(checkout)):
          Anum.append(checkout[i][1])

          for i in range(0,len(Anum)):
          for j in range(0,len(books)):
          if(Anum[i] == books[j][0]):
          title.append(books[j][1])

          final=[]
          for i in range(0,len(checkout)):
          final.append(date[i]+’~’+name[i]+’~’+Anum[i]+’~’+title[i])
          final.sort()
          for i in range(0,len(final)):
          print(final[i])

          books=[]
          borrower=[]
          checkout=[]
          x=input()
          x=input()
          while x!=’Borrowers’:
          x=x.split(‘~’)
          books.append(x)
          x=input()
          borrowers_input(borrower)
          borrower.sort()
          checkouts_input(checkout)
          output()

  5. Need the solution for week 5 programming assignment.. what you have uploaded is practice programming.. please check and upload the code as soon as possible.. due date is today.. thanks in advance..

  6. def borrowers_input(b):
    x=input()
    while x!=’Checkouts’:
    x=x.split(‘~’)
    b.append(x)
    x=input()

    def checkouts_input(c):
    x=input()
    while x!=’EndOfInput’:
    x=x.split(‘~’)
    c.append(x)
    x=input()

    def output():
    global books,borrower,checkout
    date=[]
    uname=[]
    name=[]
    Anum=[]
    title=[]
    for i in range(0,len(checkout)):
    date.append(checkout[i][2])

    for i in range(0,len(checkout)):
    uname.append(checkout[i][0])

    for i in range(0,len(uname)):
    for j in range(0,len(borrower)):
    if(uname[i] == borrower[j][0]):
    name.append(borrower[j][1])

    for i in range(0,len(checkout)):
    Anum.append(checkout[i][1])

    for i in range(0,len(Anum)):
    for j in range(0,len(books)):
    if(Anum[i] == books[j][0]):
    title.append(books[j][1])

    final=[]
    for i in range(0,len(checkout)):
    final.append(date[i]+’~’+name[i]+’~’+Anum[i]+’~’+title[i])
    final.sort()
    for i in range(0,len(final)):
    print(final[i])

    books=[]
    borrower=[]
    checkout=[]
    x=input()
    x=input()
    while x!=’Borrowers’:
    x=x.split(‘~’)
    books.append(x)
    x=input()
    borrowers_input(borrower)
    borrower.sort()
    checkouts_input(checkout)
    output()

  7. WEEK 6 Programming, Data Structures and Algorithms using Python ASSIGNMENT SOLUTIONS:-
    1–THE SET V SHOULD BE A SUBSET OF U
    2–THE SETS U AND V SHOULD BE DISJOINT
    3–[98,97,89,38,67,84,89,17,25,42]
    4–[93,67,93,38,42,54,25,17]

  8. WEEK 6 Programming, Data Structures and Algorithms using Python ASSIGNMENT SOLUTIONS:-
    1–THE SET V SHOULD BE A SUBSET OF U
    2–THE SETS U AND V SHOULD BE DISJOINT
    3–[98,97,89,38,67,84,89,17,25,42]
    4–[93,67,93,38,42,54,25,17]

    pls rectify if my answers are wrong

  9. answer for this 8th assignment…..

    ________________________________________
    Find the longest palindrome
    (IARCS OPC Archive, K Narayan Kumar, CMI)
    As we all know, a palindrome is a word that equals its reverse. Here are some examples of palindromes: malayalam, gag, appa, amma.
    We consider any sequence consisting of the letters of the English alphabet to be a word. So axxb,abbba and bbbccddx are words for our purpose. And aaabbaaa, abbba and bbb are examples of palindromes.
    By a subword of a word, we mean a contiguous subsequence of the word. For example the subwords of the word abbba are a, b, ab, bb, ba, abb, bbb, bba, abbb, bbba and abbba.
    In this task you will given a word and you must find the longest subword of this word that is also a palindrome.
    For example if the given word is abbba then the answer is abbba. If the given word is abcbcabbacba then the answer is bcabbacb.
    Solution hint
    Any subword of w that is a palindrome is also a subword when w is reversed.
    Input format
    The first line of the input contains a single integer N indicating the length of the word. The following line contains a single word of length N, made up of the letters a,b,…, z.
    Output format
    The first line of the output must contain a single integer indicating the length of the longest subword of the given word that is a palindrome. The second line must contain a subword that is a palindrome and which of maximum length. If there is more than one subword palindrome of maximum length, print the one that is lexicographically smallest (i.e., smallest in dictionary order).
    Test Data:
    You may assume that 1 ≤ N ≤ 5000. You may further assume that in 30% of the inputs 1 ≤ N ≤ 300.
    Example:
    We illustrate the input and output format using the above examples:
    Sample Input 1:
    5
    abbba
    Sample Output 1:
    5
    abbba
    Sample Input 2:
    12
    abcbcabbacba
    Sample Output 2:
    8
    bcabbacb

    • Answer for the 8th assignment: Just copy and paste as it is

      import sys

      def printSubStr(st,low,high) :
      sys.stdout.write(st[low : high + 1])
      sys.stdout.flush()
      return ”
      def longestPalSubstr(st) :
      n = len(st)
      table = [[0 for x in range(n)] for y
      in range(n)]
      maxLength = 1
      i = 0
      while (i < n) :
      table[i][i] = True
      i = i + 1
      start = 0
      i = 0
      while i < n – 1 :
      if (st[i] == st[i + 1]) :
      table[i][i + 1] = True
      start = i
      maxLength = 2
      i = i + 1
      k = 3
      while k <= n :
      i = 0
      while i maxLength) :
      start = i
      maxLength = k
      i = i + 1
      k = k + 1
      print (maxLength)
      print (printSubStr(st, start,start + maxLength – 1) )

      x = input()
      st = input()
      l = longestPalSubstr(st)

  10. THE CODE WITH INDENTATION:
    def longestPalSubstr(string):
    maxLength = 1

    start = 0
    length = len(string)
    xrange=0
    low = 0
    high = 0

    for i in range(1, length):
    low = i – 1
    high = i
    while low >= 0 and high maxLength:
    start = low
    maxLength = high – low + 1
    low -= 1
    high += 1

    low = i – 1
    high = i + 1
    while low >= 0 and high maxLength:
    start = low
    maxLength = high – low + 1
    low -= 1
    high += 1

    print(maxLength)
    print (string[start:start + maxLength])

    x = (input())
    st = input()
    l = longestPalSubstr(st)

  11. import sys
    def printSubStr(st,low,high) :
    sys.stdout.write(st[low : high + 1])
    sys.stdout.flush()
    return ”

    def longestPalSubstr(st) :
    n=len(st)
    table = [[0 for x in range(n)] for y
    in range(n)]

    maxLength = 1
    i = 0
    while (i < n) :
    table[i][i] = True
    i = i + 1

    start = 0
    i = 0
    while i < n – 1 :
    if (st[i] == st[i + 1]) :
    table[i][i + 1] = True
    start = i
    maxLength = 2
    i = i + 1

    k = 3
    while k <= n :

    i = 0
    while i maxLength) :
    start = i
    maxLength = k
    i = i + 1
    k = k + 1
    print(maxLength)
    print(printSubStr(st, start, start + maxLength – 1))

    n=input()
    st = input()
    longestPalSubstr(st)

  12. def longestPalindrome():
    n = int(input())
    s = input()
    temp = “”
    for i in range(len(s)):
    for j in range(len(s)-1,i-1,-1):
    if s[i] == s[j]:
    m = s[i:j+1]
    if m == m[::-1]:
    if len(temp) <= len(m):
    temp = m
    print(len(temp))
    print(temp)

    longestPalindrome()

  13. def longestPalindrome():
    n = int(input())
    s = input()
    temp = “”
    for i in range(len(s)):
    for j in range(len(s)-1,i-1,-1):
    if s[i] == s[j]:
    m = s[i:j+1]
    if m == m[::-1]:
    if len(temp) <= len(m):
    temp = m
    print(len(temp))
    print(temp)

    longestPalindrome()

LEAVE A REPLY

Please enter your comment!
Please enter your name here