Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A)) (Ransom Note Problem) in python A kidnapper kidnaps you and writes a ransom note. He does not write it by hand to avoid having

A))

(Ransom Note Problem) in python

A kidnapper kidnaps you and writes a ransom note. He does not write it by hand to avoid having his hand writing being recognized, so he uses a magazine to create a ransom note. We need to find out, given the ransom string and magazine string, is it possible to create a given ransom note. The kidnapper can use individual characters of words.

Here is how your program should work to simulate the ransom problem, USING LISTS, no dictionaries:

  • your program should prompt the user to enter a long String to represent the magazine and another short String to represent the required ransom note.
  • your program needs to check if the magazine string contains all required characters in equal or greater number present in the ransom note.
  • your program should print true if it is possible to create the given ransom note from the given magazine, and print false otherwise.
  • Break up your code into a set of well-defined functions. Each function should include a comment block that briefly describes it, its parameters and any return values.

Example: If the magazine string is programming problems are weird

If the ransom note is: no see your program should print true as all the characters in no see exist in the magazine string.

If the ransom note is no show your program should print false as not all the characters in no show exist in the magazine string as you can see the character h does not exist.

B)) Short one

Write Python code to define a class called Student.

The Student class should have the following private fields:

  1. name to store the name of a student
  2. attend to store how many times a student attends the class
  3. grades a list of all students grades

The Student class should have the following methods:

  1. a constructor (init method)
  2. getter method for the name field
  3. attendClass method: that increments the attend field by 1 (should be called every time a student attends the class).
  4. addGrade method: adds a new grade to the grades list
  5. __str__ method: prints all students information

In the same file, write a main function to test the functionality of the Student class.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

9th Edition

0135188148, 978-0135188149, 9781642087611

More Books

Students also viewed these Databases questions

Question

_____________ The line of authority from highest to lowest levels.

Answered: 1 week ago

Question

Differentiate between gender equality and gender equity.

Answered: 1 week ago