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:
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:
The Student class should have the following methods:
In the same file, write a main function to test the functionality of the Student class.
Code for Question - A: Ransom Note Problem in python.
# Taking Magazine text from User
magazine=input("Enter Magazine Text: ")
# Taking ransom text from User
ransom=input("Enter Ransom text: ")
# Running the loop for Small Alphabets a to z
# a=97 ........................ z=122
for i in range(97,123):
c = chr(i) # Type casting - Getting alphabet using ascii value
# Check character count in magazine and ransom text
# if count of character in ransom less then count of character in
magazine
# If condition accepted and print False and loop will break
if(magazine.count(c)<ransom.count(c)):
print('False')
break
# For-Else Loop
# If loop runs without any break else condition will be
executed
else:
print('True')
Code Screenshot:
Output Screenshots:
Code for Question -B : Write Python code to define a class called Student.
# Student class to store Students data
class Student:
# Class intialization method with arguments
def __init__(self,name='', attend=0, grades=[]):
# Assigning to respected values
self.name = name
self.attend = attend
self.grades = grades
# Method to get name from Class instance object
def get_name(self):
return self.name
# Method to add attendance to Class instance object
def attendClass(self):
self.attend += 1
# Method to add grades to Class instance object
def addGrade(self, grade):
self.grades.append(grade)
def __str__(self):
result = 'Name: ' + self.name + '\n'
result += 'Number of classes attending: ' + str(self.attend) +
'\n'
result += 'Grades are: ' + str(self.grades)
return result
# Main function
if __name__=="__main__":
# Creating Class instance and passign name string
s = Student(name='Ronaldo')
# Increasing the class attendance
s.attendClass()
# Adding Grades
s.addGrade(97)
# Increasing the class attendance
s.attendClass()
# Adding Grades
s.addGrade(92)
# Printing Instance Values using class method
print(s.__str__())
Code Screenshots:
Output Screenshot:
Note: If you any Quiries, ask me in comments...
Please vote up. your vote is more valuable to me.
A)) (Ransom Note Problem) in python A kidnapper kidnaps you and writes a ransom note. He...
For each problem, you must: Write a Python program Test, debug, and execute the Python program Save your program in a .py file and submit your commented code to your Student Page. Note regarding comments: For every class, method or function you create, you must provide a brief description of the what the code does as well as the specific details of the interface (input and output) of the function or method. (25 pts.) Write a program that reads in...
Java - In NetBeans IDE: • Create a class called Student which stores: - the name of the student - the grade of the student • Write a main method that asks the user for the name of the input file and the name of the output file. Main should open the input file for reading . It should read in the first and last name of each student into the Student’s name field. It should read the grade into...
Create a java class for an object called Student which contains the following private attributes: a given name (String), a surname (family name) (String), a student ID number (an 8 digit number, String or int) which does not begin with 0. There should be a constructor that accepts two name parameters (given and family names) and an overloaded constructor accepting two name parameters and a student number. The constructor taking two parameters should assign a random number of 8 digits....
c++ I need help! create Student.h In this class, you are provided with a class skeleton for the Student type. This type should contain two member variables: a string called name a vector of doubles called grades Additionally, you should declare the following functions: A constructor which accepts a single string parameter called name A void function, addGrade which accepts a single double parameter and adds it to the grades vector A function which accepts no parameters and returns the...
In this assignment you are asked to write a python program to maintain the Student enrollment in to a class and points scored by him in a class. You need to do it by using a List of Tuples What you need to do? 1. You need to repeatedly display this menu to the user 1. Enroll into Class 2. Drop from Class 3. Calculate average of grades for a course 4. View all Students 5. Exit 2. Ask the...
PYTHON PROGRAMMING Instructions: You are responsible for writing a program that allows a user to do one of five things at a time: 1. Add students to database. • There should be no duplicate students. If student already exists, do not add the data again; print a message informing student already exists in database. • Enter name, age, and address. 2. Search for students in the database by name. • User enters student name to search • Show student name,...
Java program Program: Grade Stats In this program you will create a utility to calculate and display various statistics about the grades of a class. In particular, you will read a CSV file (comma separated value) that stores the grades for a class, and then print out various statistics, either for the whole class, individual assignments, or individual students Things you will learn Robustly parsing simple text files Defining your own objects and using them in a program Handling multiple...
We will build one Python application via which users can perform various analytics tasks on data in 2-D table (similar to Spreadsheet) format which looks like: Column Name 1 Column Name 2 Column Name 3 Column Name N … … … … … In this table, each row represents the data of one object that we are interested in. Columns, on the other hand, represent the attributes of these objects. For example, this table could represent students’ academic records. Each...
Instructions: Consider the following C++ program. At the top you can see the interface for the Student class. Below this is the implementation of the Student class methods. Finally, we have a very small main program. #include <string> #include <fstream> #include <iostream> using namespace std; class Student { public: Student(); Student(const Student & student); ~Student(); void Set(const int uaid, const string name, const float gpa); void Get(int & uaid, string & name, float & gpa) const; void Print() const; void...
Do in Python Problem 2 Assume s is a string of lower case characters. Write a program that prints the number of times the string ' lol' occurs in s For example, if s= 'azclololegghakl', then your program should print S Number of times lol occu rs is: 2 Problem 3 Assume s is a string of lower case characters Write a program that prints the longest substring of s in which the letters occur in alphabetical order. For example,...