Assignment Chef icon Assignment Chef

Browse assignments

Assignment catalog

33,401 assignments available

[SOLVED] Cse221

Lab Assignment 03 Submission Guidelines: 1.You can code all of them either in Python, CPP, or Java. But you should choose a specific language for all tasks. 2.For each task write separate python files like task1.py, task2.py, and so on. 3.For each problem, take input from files called “inputX.txt” and output at “outputX.txt”, where X is the task number. 5. Finally zip all the files and rename this zip file as per this format:LabSectionNo_ID_CSE221LabAssignmentNo_Summer2023.zip [Example:LabSection01_21101XXX_CSE221LabAssignment03_Summer2023.z ip] 6.Don’t copy from your friends. 7.You MUST follow all the guidelines, naming/file/zipping convention stated above. Failure to follow instructions will result in a straight 50% mark deduction. Task 01 [15 Points]: Somewhere in the universe, the Biannual Regional Alien Competition is taking place. There are N aliens standing in a line. You will be given a permutation of N, which denotes the height of each alien. A sequence of N numbers is called a permutation if it contains all integers from 1 to N exactly once. For example, the sequences [3,1,4,2], [1] and [2,1] are permutations, but [1,2,1], [0,1] and [1,3,4] — are not. In the competition, for each alien, the judge wants to count how many aliens are standing on its right side with a strictly smaller height. Then the judge wants to add up all the counts. To do this, the judge writes the following piece of code. count = 0 for i in range(n): for j in range(i+1,n): if H[i] > H[j]: count+=1 However, their algorithm wasn’t efficient at all. Hence, the alien calls you to write a better solution for the program. More formally, you have to count how many pairs of aliens are standing in the line such that H[i] > H[j] and i < j. Here, A is a permutation of the aliens’ heights. And i,j denote the Aliens’ positions. Input The first line contains a single integer 1

$25.00 View

[SOLVED] Cse221

Lab Assignment 02 Submission Guidelines: 1.You can code all of them either in Python, CPP, or Java. But you should choose a specific language for all tasks. 2.For each task write separate python files like task1.py, task2.py, and so on. 3.For each problem, take input from files called “inputX.txt” and output at “outputX.txt”, where X is the task number. 5. Finally zip all the files and rename this zip file as per this format:LabSectionNo_ID_CSE221LabAssignmentNo_Summer2023.zip [Example:LabSection01_21101XXX_CSE221LabAssignment02_Summer2023.z ip] 6.Don’t copy from your friends. 7.You MUST follow all the guidelines, naming/file/zipping convention stated above. Failure to follow instructions will result in a straight 50% mark deduction. Task 01: [Points: 15] Alice will give you an integer, S. You have to find if it is possible to find two values from the list (at distinct positions) whose sum is equal to S. Now you are feeling very tired. So you decided to write a code, so that it can give you the answer very quickly. 1)Can you write an O(n2) Solution to solve the problem? [Points 5] 2)Come up with an O(n) or O(nlogn) solution. [Points 10] Input 5 The first line contains two integers N and S (1

$25.00 View

[SOLVED] Cse221: algorithms

Lab Assignment 01 Submission Guidelines: 1. You can code all of them either in Python, Java or CPP. But you should choose a specific language for all tasks. 2. For each task write separate python files like task1.py, task3.py and so on. 3. For each problem, take input from files called “inputX.txt”, and output at “outputX.txt”, where X is the task number. So, for problem 2, in your code, the input file is basically this, “input2.txt”. Same for the output file. 4. Finally zip all the files and rename this zip file as per this format: LabSectionNo_ID_CSE221LabAssignmentNo_Summer2023.zip. [Example: LabSection01_21101XXX_CSE221LabAssignment01_Summer2023.zip] 5. You MUST follow all the guidelines, and naming/file/zipping convention stated above. Failure to do so will result in a straight 50% mark deduction. Task 1: a) You are given a file “input1a.txt”. The first line of the input file will contain an integer T, representing the number of test cases. The next T lines will contain an integer N. You have to calculate if the number is Odd or Even. For each test case print the expected output. All the results must be compiled in a single file, “output1a.txt.” Sample Input File Sample Output File 5 10 19 7 3 100 10 is an Even number. 19 is an Odd number. 7 is an Odd number. 3 is an Odd number. 100 is an Even number. b) You are given a file “input1b.txt”. The first line of the input file will contain an integer T, representing the number of test cases. The next T lines will contain a single arithmetic expression. Each arithmetic expression will start with the prefix “calculate“. It is guaranteed that the expression will have exactly two operands and one operator. Calculate the result of each expression. Your output format should exactly match with the sample output format. All the results must be compiled in a single file, “output1b.txt.” Sample Input File Sample Output File 15 calculate 67 + 41 calculate 85 / 5 calculate 13 – 56 calculate 99 – 95 calculate 3 / 10 calculate 12 * 19 calculate 14 – 6 calculate 3 * 88 calculate 45 * 68 calculate 81 – 0 calculate 77 + 40 calculate 8 * 84 calculate 73 – 22 calculate 85 – 86 calculate 28 * 58 The result of 67 + 41 is 108 The result of 85 / 5 is 17.0 The result of 13 – 56 is -43 The result of 99 – 95 is 4 The result of 3 / 10 is 0.3 The result of 12 * 19 is 228 The result of 14 – 6 is 8 The result of 3 * 88 is 264 The result of 45 * 68 is 3060 The result of 81 – 0 is 81 The result of 77 + 40 is 117 The result of 8 * 84 is 672 The result of 73 – 22 is 51 The result of 85 – 86 is -1 The result of 28 * 58 is 1624 Task 2: Here is the code of bubble sort. Its run time complexity is θ(n2). Change the code in a way so that its time complexity is θ(n) for the best-case scenario. You have to explain how you have achieved the θ(n) for the best-case scenario in a comment block of your code. def bubbleSort(arr): for i in range(len(arr)-1): for j in range(len(arr)-i-1): if arr[j] > arr[j+1]: arr[j], arr[j+1] = arr[j+1], arr[j] Input 1: 5 3 2 1 4 5 Output 1: 1 2 3 4 5 Input 2: 6 5 10 15 20 25 30 Output 2: 5 10 15 20 25 30 For the input 2, your code should run at θ(n). Task 3: However, you have to keep in mind that your sorting algorithms perform the minimum number of swapping operations. Input: The first line of the input file will contain an integer N ( 1 ≤ N ≤ 1000 ). The second line will contain N integers, representing the Student ID, Si ( 1 ≤ Si ≤ 1000 ). The next line will contain the N integer, Sm ( 1 ≤ Sm ≤ 1000 ), which denotes the obtained mark of the corresponding students. Output: Input 1: 7 7 4 9 3 2 5 1 40 50 50 20 10 10 10 Output 1: ID: 4 Mark: 50 ID: 9 Mark: 50 ID: 7 Mark: 40 ID: 3 Mark: 20 ID: 1 Mark: 10 ID: 2 Mark: 10 ID: 5 Mark: 10 Input 2: 4 7 2 5 3 80 60 80 50 Output 2: ID: 5 Mark: 80 ID: 7 Mark: 80 ID: 2 Mark: 60 ID: 3 Mark: 50 Task 4: Your task is to write a sorting algorithm that will group the trains in the lexicographical order based on the name of the trains. If two or more trains have the same name, then the train with the latest departure time will get prioritized. If there is still a tie, then the train which comes first in the input file will come first. Sample Input Sample Output 13 ABCD will departure for Mymensingh at 00:30 DhumketuExpress will departure for Chittagong at 02:30 SubornoExpress will departure for Chittagong at 14:30 ABC will departure for Dhaka at 17:30 ShonarBangla will departure for Dhaka at 12:30 SubornoExpress will departure for Rajshahi at 14:30 ABCD will departure for Chittagong at 01:00 SubornoExpress will departure for Dhaka at 11:30 ABC will departure for Barisal at 03:00 PadmaExpress will departure for Chittagong at 20:30 ABC will departure for Khulna at 03:00 ABCE will departure for Sylhet at 23:05 PadmaExpress will departure for Dhaka at 19:30 ABC will departure for Dhaka at 17:30 ABC will departure for Barisal at 03:00 ABC will departure for Khulna at 03:00 ABCD will departure for Chittagong at 01:00 ABCD will departure for Mymensingh at 00:30 ABCE will departure for Sylhet at 23:05 DhumketuExpress will departure for Chittagong at 02:30 PadmaExpress will departure for Chittagong at 20:30 PadmaExpress will departure for Dhaka at 19:30 ShonarBangla will departure for Dhaka at 12:30 SubornoExpress will departure for Chittagong at 14:30 SubornoExpress will departure for Rajshahi at 14:30 SubornoExpress will departure for Dhaka at 11:30

$25.00 View

[SOLVED] Cse220 – tree [co2]

Instructions for students: ● Complete the following methods on Tree. ● All your methods must be written in one single .java or .py or .pynb file. DO NOT CREATE separate files for each task. ● If you are using JAVA, you must include the main method as well which should test your other methods and print the outputs according to the tasks. ● If you are using PYTHON, then follow the coding templates shared in this folder. NOTE: ● YOU CANNOT USE ANY BUILT-IN FUNCTION EXCEPT len IN PYTHON. [negative indexing, append is prohibited] ● YOU HAVE TO MENTION SIZE OF ARRAY WHILE INITIALIZATION ● YOUR CODE SHOULD WORK FOR ALL RELEVANT SAMPLE INPUTS ● DO NOT USE LIST, QUEUE Given a binary tree, convert it into its mirror. Sample Input: 10 / 20 30 / 40 60 Sample Output: 10 10 / Mirror / 20 30 —> 30 20 / / 40 60 60 40 Inorder Traversal of mirror: 30 10 60 20 40 Given a binary tree, find the smallest value in each level. Sample Input: [You can use dictionary/list here.] 4 / 2 9 / / 7 3 -5 Sample Output: 4 2 -5 Explanation: There are 3 levels in the tree Level 0: {4}, min= 4 Level 1: {2, 9}, min= 2 Level 2: {7, 3, -5}, max = -5 Given a BST, and a reference to a Node x in the BST, find the Inorder Predecessor of the given node in the BST. DO NOT USE LIST Sample Input: 20 / 8 22 / 4 12 / 10 14 x = reference of the node containing 20 Sample Output: reference of the node 14 Explanation: The inorder predecessor of a parent node is the largest (rightmost) node in the left subtree. The rightmost node in the left subtree of parent node 20 is 14. Another explanation is that, the inorder traversal of the given tree: 4 8 10 12 14 20 22 Hence, the inorder successor of 20 is 14. Sample Input 2: x = reference of the node containing 8 Sample Output: reference of the node 4 The lowest common ancestor (LCA) of two nodes x and y in the BST is the lowest (i.e., deepest) node that has both x and y as descendants. In other words, the LCA of x and y is the shared ancestor of x and y that is located farthest from the root. Corner Case: if y lies in the subtree rooted at node x, then x is the LCA; otherwise, if x lies in the subtree rooted at node y, then y is the LCA. LCA(6,12) = 10 LCA(20,6) = 15 LCA(18,22) = 20 LCA(20,25) = 25 LCA(10,12) = 10 Given a Binary Tree, Write a function that finds if the given Binary Tree is SumTree. A SumTree is a Binary Tree where the value of a node is equal to the sum of the nodes present in its left subtree and right subtree. An empty tree is SumTree and the sum of an empty tree can be considered as 0. A leaf node is also considered as SumTree. Sample Input: Sample Output 26 / 10 3 / 4 6 3 True Given a Binary Tree, Write a function that finds the difference between sum of all nodes present at odd and even levels in a binary tree, i.e. sum of all odd level nodes – sum of all even level nodes. Sample Input: Sample Output Explanation 4 -1+2+3-4-5-6+7+8 = 4

$25.00 View

[SOLVED] Cse220 – instructions for students:

1. Complete the following problem using concepts of RECURSION 4. The submission format MUST be maintained. You need to copy paste all your codes in ONE SINGLE .ipynb file and upload that. If format is not maintained, whole lab submission will be canceled. 5. If you are using JAVA, you must include the main method as well which should test your other methods and print the outputs according to the tasks. 6. If you are using PYTHON, make sure your code has the methods invoked and proper printing statements according to the tasks. 7. NO USE OF LOOP OR ANY OTHER BUILT IN FUNCTION UNTIL EXPLICITLY MENTIONED Assignment Tasks: [CO4] a) Implement a recursive algorithm that takes an array and adds all the elements of the array. b) The total number of combinations of size r from a set of size n [where r is less than or equal to n], we use the combination nCr where the formula is: C(n,r)=n!/r!(n-r!) Given n and r [r

$25.00 View

[SOLVED] Cse220 – hashing and collision resolve [co3]

Instructions for students: ● Complete the following methods on Hashing. ● All your methods must be written in one single .java or .py or .pynb file. DO NOT CREATE separate files for each task. ● If you are using JAVA, you must include the main method as well which should test your other methods and print the outputs according to the tasks. ● If you are using PYTHON, then follow the coding templates shared in this folder. NOTE: ● YOU CANNOT USE ANY BUILT-IN FUNCTION EXCEPT len IN PYTHON. [negative indexing, append is prohibited] ● YOU HAVE TO MENTION SIZE OF ARRAY WHILE INITIALIZATION 1. Nerdy Run: (Easy) A group of game developers released a math game named ‘Nerdy Run’. In this game, there is a lengthy straight path that contains some numbers and a random number k. As you walk on the path, your goal is to find out if the path contains any duplicates within k distance. If you find a duplicate within k distance, you will type the number in a textbox; if not type None. The constraint is that, the game control allows you to move only once and move forward. There is no backward movement controller in this game. Constraint: 1. DO NOT USE Membership Operators in List, String for this task. 2. You can traverse the array ONLY ONCE and Always Move Forward (i.e. no nested loop). Sample Input: path = [6,7,8,9,5,9] k = 3 Sample Output: 9 Explanation: The number 9 has a duplicate at 2 distances away which is less than k(3). Therefore, the found duplicate within 3 distances is 9. Sample Input: path = [6,7,9,6,5,9] k = 2 Sample Output: None Explanation: No number repeated within distance 2 Sample Input: path = [0.21,1.21,4.67,0.21,0.45,1.9] k = 7 Sample Output: 0.21 2. Hashtable with Forward Chaining: (Medium) Complete the __hash_function() and search_hashtable() methods in the given colab file . Do not change the given code; implement only the required methods. Creating and Inserting into a hash table using forward chaining is already done in the class. Do not initialize any other instance variable other than the given ones. a. search_hashtable(self,s) → this instance method takes a string s and searches for the string in the instance variable ht. If the string s is found, this method returns ‘Found’, else returns ‘Not Found’. (Do not implement sequential search, implement the hash based search.) b. __hash_function(self,s) → this instance method takes a key-value pair (string, int), calculates the hashed index on key and returns the index. This hash function takes consecutive two letters of the key string, concatenates their ascii values into an integer and sums all the concatenated integers. Then it finds out the modulus of the summation (think for yourself with which number should we mod the summation) as the hashed index. For instance, for a string ‘Mortis’, the consecutive two letters are Mo, rt, is. The concatenated integer for Mo is 77111 (Ascii of M is 77, o is 111); rt is 114116 (Ascii of r is 114, t is 116); ‘is’ is 105115 (Ascii of i is 105, s is 115). The summation is = 77111+114116+105115 Mod the summation with __________ (fill in the gap) and return the answer as the hashed index. (As for an odd length string, add the letter ‘N’ at the end of it. Thus, ‘Morti’ becomes ‘MortiN’ and the consecutive two letters are Mo, rt, iN) 3. Layered Hashtable: (Hard) Complete the create_layered_hashtable() and search_element() methods in the given colab file. Do not change the given code; implement only the required methods. Printing the layered hashtable is already implemented in the class. You can take enough hints from the printing method. Do not initialize any other instance variable other than the given ones. Let us learn a new type of hashing data structure for sorted linked lists. As you already know, searching in linked lists always requires a sequential search loop as there is no indexing (direct access) in this ADT (abstract data structure). So, to lessen the number of times a loop runs, we will use an array (of specific length) named express_lane. This array serves as the hashtable for sorted linked lists. This express_lane contains some specific nodes of a sorted linked list. The nodes stored in express_lane[i] and express_lane[i+1] represent all the other nodes in the sorted linked list (normal lane). For example, Suppose, the size of an express_lane is 4. Then, for the sorted linked list (normal lane): 4→6→9→18→25→37→62→67→79→84 The express_lane will be: 4 18 62 84 Here, each element in the express_lane is the node of the given linked list. Therefore, 4 in the express_lane indicates the node 4 in the given linked list (normal lane) and so on and so forth.a. create_layered_hashtable(self, linked_list_head): This method takes a sorted linked list(normal lane) and creates the express lane of a specific size. Bucket: A bucket is the nodes represented by the nodes stored in express_lane[i] and express_lane[i+1]. In the mentioned example, express_lane[0] contains node 4 express_lane[1] contains node 18 Therefore, this bucket represents all the nodes that are greater or equal to 4 and smaller than 18: 4→6→9→ express_lane[1] contains node 18 express_lane[2] contains node 62 Therefore, this bucket represents all the nodes that are greater or equal to 18 and smaller than 62: 18→25→37→ Which node to store in the express_lane array: First we identify the bucket size. For simplicity, to get the bucket size, we divide the number of nodes in the normal lane by the express_lane size. In the mentioned example, for express lane size 4, bucket size = (number of nodes in the normal lane/4)+1 = 10/4 +1 = 3 It indicates that every bucket has 3 nodes. The express_lane contains the normal lane nodes whose positions are divisible by bucket size. In the mentioned example, node 4 is at 0th index Node 18 is at 3rd index Node 62 is at 6th index Node 84 is at 9th index Thus the express_lane contains nodes: 4 18 62 84 b. search_element(self,k): This method searches for k in the given sorted linked list and returns ‘Found’/ ‘Not Found’. (Do not implement sequential search, implement the hash based search.) Suppose we need to search for an element in the sorted normal lane. Before, we needed to iterate through the whole linked list. In this layered hashtable, we need to find which bucket can possibly contain the element and iterate through only those nodes. Since the normal lane is sorted, finding a bucket is easy. We need to find such an i in express_lane so that express_lane[i].element

$25.00 View

[SOLVED] Cse220 –

Course Code: CSE 220 Credits: 1.5 Course Name: Data StructuresLab 05 Parenthesis BalancingI. Topic Overview: Students will learn a practical use case for stack data structure. By implementing and using stacks methods, they will learn to check whether a given expression has balanced parentheses or brackets.II. Lesson Fit: For successfully completing this lab’s tasks, the students need to have a good idea on how stack is implemented and how the various methods such as push(), pop() etc works. They also need a clear idea about array and linked list as both of these data structures are used to create a stack. Moreover, students need a solid grasp on programming in Java and Java IDE. III. Learning Outcome: a. Understand the functionality of stack data structure b. Use stack methods to solve programming problems c. Implement stack ADT using both array and linked list IV. Anticipated Challenges and Possible Solutions a. Students might find it difficult to implement stack using array or linked list or both. For example, in array based implementation, students have to check for stack overflow and underflow exceptions. Also, in case of linked list based implementation, only stack underflow condition needs to be checked. Solutions: i. Students have to create class for stack related exceptions. Two different classes can be declared, one for overflow and one for underflow. Both classes need to extend the Exception class of Java. ii. Put stack’s push and pop methods inside a try-catch block and handle the exceptions. b. It can get difficult or confusing to check all conditions of parenthesis matching. Because, when a closing parenthesis/curly brace/bracket is encountered one needs to make sure the correct type of opening parenthesis/curly brace/bracket are popped from the stack Solutions: i. Students need to write if-else if checking for each type of parenthesis/curly brace/bracket separately when an opening parenthesis/curly brace/bracket is encountered. ii. Also, a method to check whether the stack is empty after reading all inputs needs to be implemented.V. Acceptance and EvaluationInstructions for students:3. You need to create a full functioning Stack data structure to solve this problem. You are not allowed to use the built in Stack. 5. The submission format MUST be maintained. You need to copy paste all your codes in ONE SINGLE .txt file and upload that. If format is not maintained, whole lab submission will be canceled. 6. If you are using JAVA, you must include the main method as well which should test your other methods and print the outputs according to the tasks. 7. If you are using PYTHON, make sure your code has the methods invoked and proper printing statements according to the tasks.Lab 04 Activity List Input Your program will take an arithmetic expression as a String input. For Example:1. “1+2*(3/4)”2. “1+2*[3*3+{4–5(6(7/8/9)+10)–11+(12*8)]+14”3. “1+2*[3*3+{4–5(6(7/8/9)+10)}–11+(12*8)/{13+13}]+14”ProgramYour program will determine whether the open brackets (the square brackets, curly braces and the parentheses) are closed in the correct order.Outputs:Output 11+2*(3/4) This expression is correct.Output 21+2*[3*3+{4–5(6(7/8/9)+10)–11+(12*8)]+14 This expression is NOT correct. Error at character # 10. ‘{‘- not closed.Output 31+2*[3*3+{4–5(6(7/8/9)+10)}–11+(12*8)/{13+13}]+14 This expression is correct.Output 41+2]*[3*3+{4–5(6(7/8/9)+10)–11+(12*8)]+14 This expression is NOT correct. Error at character # 4. ‘]‘- not opened. Task 1 Solve the above problem using an array based stack.Task 2 Solve the above problem using a linked list based stack.

$25.00 View

[SOLVED] Cse220 – lab 04 [co3]

Greetings Students. In this lab, we will play with Dummy Headed Doubly Circular Linked List. If you want to read about this type of linked list then check this file. In this lab, you have to implement a waiting room management system in an emergency ward of a hospital. Your program will serve a patient on a first-come-first-serve basis.Solve the above problem using a Dummy Headed Doubly Circular Linked List. 1. You need to have a Patient class so that you can create an instance of it (patient) by assigning id(integer), name (String), age (integer), and blood group (String). 2. Write a WRM (waiting room management) class that will contain the below methods. a. RegisterPatient(id, name, age, bloodgroup): This method will register a patient into your system. The method will create a Patient type object with the information received as parameter. It means this method will add a patient-type object to your linked list. b. ServePatient(): This method calls a patient to provide hospital service to him/her. In this method, you need to ensure to serve the patient first who was registered first. c. CancelAll(): This method cancels all appointments of the patients so that the doctor can go to lunch. d. CanDoctorGoHome(): This method returns true if no one is waiting, otherwise, returns false. e. ShowAllPatient(): This method prints all names of the waiting patients in sequential order. It means the patient who got registered first, will come first, and so on. f. ReverseTheLine(): This method reverses the patient line. It means the patient who got registered last, will come first, and so on. 3. Write a Tester code that will interact with users and take information about Patients. You will pass this information to WRM and create instances of Patient in WRM and call the methods of WRM class. You just need to ensure your Tester code has completed all the properties mentioned in 4 no point. 4. Tester Code Options: a. Add Patient – print Success or Not b. Serve Patient – print Name of Patient being Served c. Show All patients – print all patient in sequence to serve d. Can Doctor go Home? – return yes or no e. Cancel all Appointment – print Success or Not f. ReverseTheLine – print Success or Not Hints: Usual Node class design in doubly linked list: class DoublyNode: def __init__(self, elem, next, prev): self.elem = elem self.next = next # To store the next node’s reference. self.prev = prev # To store the previous node’s reference. In your program your Patient class will work as the Node class for the Dummy Headed Doubly Circular Linked List and WRM class will work as that Linked List.

$25.00 View

[SOLVED] Cse220 – singly linked list [co3]

Instructions for students: ● Complete the following methods on Singly Linked List. ● All your methods must be written in one single .java or .py or .pynb file. DO NOT CREATE separate files for each task. ● If you are using JAVA, you must include the main method as well which should test your other methods and print the outputs according to the tasks. ● If you are using PYTHON, then follow the coding templates shared in this folder. NOTE: ● YOU CANNOT USE ANY OTHER DATA STRUCTURE OTHER THAN LINKED LIST ● YOUR CODE SHOULD WORK FOR ANY VALID INPUTS. [Make changes to the Sample Inputs and check whether your program works correctly] ● LOOK OUT FOR 0th NODE Condition Tasks on Linked List 1. Number Beads Amy Santiago and her son Mac were playing with number beads. Amy decided to make a chain with those beads. Being the way she is, Amy decided to place the numbers in the necklace in a descending order. For example, she placed the numbers in such a way: 20, 17, 13, 10, 6. But her spouse Jake wished to tease her. And so, he right rotated the number beads a number of times without showing Amy. Then he showed the rearranged necklace and told her to guess the number of times he rotated the necklace. Can you help Amy by writing a method that takes the rearranged number beads and returns the number of times the necklace was right rotated? Sample Input Sample Output Explanation 13→10→6→20→17→None 3 The original sequence: 20→17→13→10→6 After Right Rotation 1: 6→20→17→13→10 After Right Rotation 2: 10→6→20→17→13 After Right Rotation 3: 13→10→6→20→17 Therefore, the necklace was rotated 3 times. 6→20→17→13→10→None 1 Building Blocks Your twin and you are under an experiment where the amount of thinking similarities you two have is being observed. As per the experiment, you are given the same number of building blocks of different colors and are told to make a building using those blocks in two different rooms. After the buildings are finished, the observers check whether the two buildings are the same based on the block colors. Now, you are the tech guy of that team and you are instructed to write a program that will output “Similar” or “Not Similar” given the two buildings. For fun, you decided to represent those buildings as a linked list! NB: Red means a red block Blue means a blue block Yellow means a yellow block Green means a green block. Sample Input Sample Output building_1 = Red→Green→Yellow→Red→Blue→Green→None building_2 = Red→Green→Yellow→Red→Blue→Green→None Similar building_1 = Red→Green→Yellow→Red→Yellow→Green→None building_2 = Red→Green→Yellow→Red→Blue→Green→None Not Similar building_1 = Red→Green→Yellow→Red→Blue→Green→None building_2 = Red→Green→Yellow→Red→Blue→Green→Blue→None Not SimilarRemove Compartment Sample Input Sample Output 14→10→15→10→41→10→72 number = 10 14→10→15→10→41→72 10→15→34→41→56→72 number = 7 10→15→34→41→56→72 33→15→34→41→56→72 number = 33 15→34→41→56→72 Sheldon is a train maniac. He loves attaching each compartment of a train to the next with a linking chain as his hobby. Each train compartment is associated with a number. Now he is removing the last occurrence of a particular train compartment from the train. Can you model the scenario by writing a method that takes the compartment sequence and a number; the method returns the changed (or unchanged) train compartment sequence. Constraint: a. You cannot create any new linked list. You have to change the given one. Capture the Flag Sample Input: Sample Output: Explanation 11→8→21→20→5→42 →None 11→4→7→5→1→7 →None 11 is at position 1. Since 1*11 = 11, the node in resulting linked list has 11 in position 1 8 is at position 2. Since 2*4 = 8, the node in resulting linked list has 4 in position 2 21 is at position 3. Since 3*7 = 21, the node in resulting linked list has 7 in position 3 11→8→28→20→5→42 →None Linkwise 28 is at position 3. Since 28%3 != 0, the result is a string Linkwise. There is a competition called CTF (Capture the flag). It’s basically a competition about cyber security where you will be provided a range of questions from different categories (from easy level to level extreme) and you have to find out the answers (aka flags) of those questions. [If you are interested, you can solve interesting problems from here] Suppose, you are playing a CTF with your friends where you are given a series of numbers as clues. If all the numbers are a multiple of its corresponding position [1 based], then the flag will be a newly created linked list consisting of the factors of the numbers. If not, then the flag will be a string ‘Linkwise’. Shuffle on Song Sample Input: Sample Output: S→E→N→P→A→I N→P→S→E→A→I N→I→S→H→I→N→O→Y→A N→H→N→I→S→I→O→Y→A In a Music player , the next button gives you the next song and the previous button moves back to the previous one. For simplicity, suppose our designed music player only has a next button. However, our music player has a special button named ‘shuffle on song’. The button creates another playlist from the given playlist where all the songs with even ascii value will be linked in the beginning and the odd ascii valued songs are linked in the end. The relative position of the song remains unchanged. Implement the ‘shuffle on song’ button that takes a playlist and returns a newly created playlist. Given playlist will contain at least two songs.BONUS Assemble Conga Line Have you ever heard the term conga line? Basically, it’s a carnival dance where the dancers form a long line. Everyone holds the waist of the person in front of them and their waists are held in turn by the person to their rear, excepting only those in the front and the back. It kind of looks like this-By now, you can quite understand the suitable data structure to represent a conga line. Now you are the choreographer of the Conga Dance in a Summer Festival. You have arranged an ascending conga line based on the participants’ age. But you feel like this year’s conga line is a bit short. You want to add one more person in a certain position in the conga line (maintaining the ascending order). There are other candidates willing to join the line. You have to pick a candidate from that pool to add in your conga line in the specified position [0 based]. Now as technical you are, can you write a method that will take the conga line, the candidate line and the insertion index and return the resulting conga line? Constraint: b. You cannot create any new linked list. You have to change the given one. c. Pick a candidate whose age is closer to the person in the inserting index in the conga line Sample Input conga_line = 10→15→34→41→56→72 candidate_line = 16→2→36→52→40→77 →None insertion_idx = 3 Sample Output conga_line = 10→15→34→40→41→56→72 Explanation: To insert a candidate in the 3rd index in conga line, you need to pick someone within 34-41. The possible candidates are 36 and 40. Since, 40 is closer to 41, we choose 40 to be inserted in the 3rd index.

$25.00 View

[SOLVED] Cse220 – multidimensional arrays [co1]

Instructions for students: ● Complete the following methods on 2D Arrays ● All your methods must be written in one single .java or .py or .pynb file. DO NOT CREATE separate files for each task. ● If you are using JAVA, you must include the main method as well which should test your other methods and print the outputs according to the tasks. ● If you are using PYTHON, then follow the coding templates shared in this folder. NOTE: ● YOU CANNOT USE ANY BUILT-IN FUNCTION EXCEPT len IN PYTHON. [negative indexing, append is prohibited] ● You can use the attribute ‘shape’ of numpy arrays ● YOU HAVE TO MENTION SIZE OF ARRAY WHILE INITIALIZATION ● YOUR CODE SHOULD WORK FOR ANY VALID INPUTS. [Make changes to the Sample Inputs and check whether your program works correctly] 2D Array tasks: 1. Zigzag Walk: As a child, you often played this game while walking on a tiled floor. You walked avoiding a certain color, for example white tiles (it almost felt like if you stepped on a white tile, you would die!). Now you are in a room of m x n dimension. The room has m*n black and white tiles. You step on the black tiles only. Your movement is like this: ORNow suppose you are given a 2D array which resembles the tiled floor. Each tile has a number. Can you write a method that will print your walking sequence on the floor? Constraint: The first tile of the room is always black. Hint: Look out for the number of rows in the matrix [Notice the transition from column 0 to column 1 in the above figures]Sample Input Sample Output ——————– | 3 | 8 | 4 | 6 | 1 | ——————– | 7 | 2 | 1 | 9 | 3 | ——————– | 9 | 0 | 7 | 5 | 8 | ——————– | 2 | 1 | 3 | 4 | 0 | ——————– | 1 | 4 | 2 | 8 | 6 | ——————– 3 9 1 1 2 4 7 2 4 9 1 8 6 ——————– | 3 | 8 | 4 | 6 | 1 | ——————– | 7 | 2 | 1 | 9 | 3 | ——————– | 9 | 0 | 7 | 5 | 8 | ——————– | 2 | 1 | 3 | 4 | 0 | ——————– 3 9 1 2 4 7 4 9 1 8 2. Wall Up Trost District: You live in the Trost District. There was a wall (named Wall Rose) around your district for protection of the attacks from giants (named Titans). One day, the wall got destroyed and the district council decided to build a new wall around your district. The design of the district is rather intriguing. It is shaped like a 2D matrix. To create a wall around the district is equivalent to padding the array all around with a certain number. In the council, it was decided that the padding number would be 8 and the depth of the wall would be decided by the council head. Now, given the matrix representation of your district and the depth of the wall, write a method that will create a new 2D array and print the resultant array [the district array surrounded by padding of 8]. Sample Input Sample Output district = —————– | 2 | 3 | 4 | —————– | 3 | 4 | 6 | —————– | 2 | 1 | 4 | —————– depth = 1 | 8 | 8 | 8 | 8 | 8 | ——————————- | 8 | 2 | 3 | 4 | 8 | ——————————- | 8 | 3 | 4 | 6 | 8 | ——————————- | 8 | 2 | 1 | 4 | 8 | ——————————- | 8 | 8 | 8 | 8 | 8 | ——————————- district = ———————- | 2 | 3 | 4 | 1 | ———————- | 3 | 4 | 6 | 5 | ———————- | 2 | 1 | 4 | 7 | ———————- depth = 2 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | ———————————————– | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | ———————————————– | 8 | 8 | 2 | 3 | 4 | 1 | 8 | 8 | ———————————————– | 8 | 8 | 3 | 4 | 6 | 5 | 8 | 8 | ———————————————– | 8 | 8 | 2 | 1 | 4 | 7 | 8 | 8 | ———————————————– | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | ———————————————– | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | ———————————————– 3. Crows vs Cats: In your prefecture, there are two volleyball teams who are dubbed as Crow and Cat. They often engage in volleyball matches in their clubroom. The clubroom is square in shape and the volleyball net is along the primary diagonal. In the match, Crows stand in the upper right corner of the net and cats in the lower left corner. To exchange greetings in the beginning, they stand in a matrix position. Now given a 2D matrix ‘clubroom’, where the primary diagonal is the net, upper triangle is the Crow, lower triangle is the Cat; write a method that calculates the difference in strength between the Crow player and its mirrored Cat Player and store them in a array named ‘strength_diff’. Note: The length of ‘strength_diff’

$25.00 View

[SOLVED] Cse220 – (playing with array and probability theory)

Greetings Students. Do not panic after watching the title of this lab. We are not going to teach you probability theory in depth (at least not in this lab!!!). In this lab, we will play with numbers and arrays. In this lab, you are going to implement something from the scratch!!! The lab task is divided into three parts. What are the parts!!!1. You need to find the mean of a series of numbers stored in an array. 2. You need to calculate the sample standard deviation of those numbers. 3. You need to create a new array where you will only store the numbers that are at least 1.5 standard deviations away from the mean.If you are wondering “I don’t know all the theories for calculating all these mean and standard deviations!!!!!” Just spare some time to follow the links:● How to calculate the mean and standard deviation: https://youtu.be/IaTFpp-uzp0 ● How to find numbers that are a certain Standard Deviation away from the mean: ● Mean calculation: https://www.mathsisfun.com/mean.html ● Standard deviation calculation: https://www.mathsisfun.com/data/standard-deviationformulas.html (Use Sample Standard Deviation Formula (N – 1))For example, if you are dealing with an array with the following numbers:[10, 8, 13, 9, 14, 25, -5, 20, 7, 7, 4]The mean of the numbers is: 10.181818181818The standard deviation is: 7.96New array: [25, -5]Explanation:The mean of the numbers is 10.18 and the standard deviation is 7.96. Only 25 and -5 are at least 1.5 standard deviations away from the mean. And so the new array’s length is 2 and only two items are copied.Hints to implement this program:1. Create a function that will take an array and return the mean of the values 2. Create a function that will take an array and return the standard deviation of the values 3. Create a function that will take an array and create a new array whose length will be the total number of values of the array which are 1.5 standard deviations away from the mean of that array. Finally, return the new array. If there is no such value then return None. 4. Write the driver code and call the above-created functions. You can use an array with your preferable length and values to test your program.Try this code, solving this might be a fun experience. And remember,Confusion is part of programming. ― Felienne Hermans

$25.00 View

[SOLVED] Cse220 – linear arrays [co5]

Instructions for students: ● Complete the following methods on Arrays ● All your methods must be written in one single .java or .py or .pynb file. DO NOT CREATE separate files for each task. ● If you are using JAVA, you must include the main method as well which should test your other methods and print the outputs according to the tasks. ● If you are using PYTHON, then follow the coding templates shared in this folder. NOTE: ● YOU CANNOT USE ANY BUILT-IN FUNCTION EXCEPT len IN PYTHON. [negative indexing, append is prohibited] ● YOU HAVE TO MENTION SIZE OF ARRAY WHILE INITIALIZATION ● YOUR CODE SHOULD WORK FOR ANY VALID INPUTS. [Make changes to the Sample Inputs and check whether your program works correctly] ● Use Numpy array to initialize the array. You are allowed to use the shape parameter of the numpy array as well. ● DO NOT USE DICTIONARY Array Tasks: 1. Play Right!: Suppose you are having a party with your friends. Your friends are playing a game similar to pillow passing. In this game they stand in a line and with each beat of the music they change their position. When the beat is high, they move one position right and when the beat is low they remain still. As for the person standing at the end of the line, with a high change of beat he/she runs to the beginning. Now you are not allowed to participate in the game because you didn’t bring enough cola for everyone! Rather, they decided to play a game on you. They will give you their standing sequence in an array where each element is their ID and another array where low beat is denoted as 0 and high beat is denoted as 1. With this information you have to tell their final standing sequence within seconds! Now as a CS student, implement the scenario using a proper method where two arrays are taken as parameters and return the resulting array. Sample Input / Driver Code: sequence=[10,20,30,40,50,60] beats = [1,0,0,1,0,1] #Function Call: print(playRight(sequence,beats)) Sample Output: [40, 50, 60, 10, 20, 30] Discard Cards: This time you guys are playing a card game. You pick n numbers of UNO cards from the deck. The rule of the card game is- one person says a number and you have to discard the cards with the same number from your hand without changing the relative position of other cards. Implement the scenario using a proper method which takes the cards in your hands as an array and a number as parameters; and returns the resulting array. Sample Input / Driver Code: cards=[10,2,30,2,50,2,2,0,0] #Function Call: print(discardCards(cards,2)) Sample Output: [10,30,50,0,0,0,0,0,0]Merge Lineup: Now you guys are playing a 2v2 fierce pokemon battle. At one point your and your teammate’s pokemons have very low hp. So you created a new rule to merge the hp of your and your teammate’s pokemons and create a new pokemon lineup. But the opposite team placed a special condition. You and your teammate have to add the hp of your team’s pokemons from opposite directions. That is, your first pokemon’s hp will be added to your teammate’s last pokemon’s hp; your second pokemon’s hp will be added to your teammate’s second last pokemon’s hp and so on and so forth. The None elements denote 0 hp. You and your teammate have the same number of pokemons. Implement the scenario using a proper method which takes your and your teammate’s pokemon hp as two arrays (as parameters); and returns the resulting arr. Sample Input / Driver Code: pokemon_1: [4, 5, -1, None, None] pokemon_2: [2, 27, 7, 12, None] #Function Call: print(mergeLineup(pokemon_1, pokemon_2)) Sample Output: [4,17,6,27,2] Explanation: 4+None(0) = 4 {pokemon_1[0]+pokemon_2[4]}, 5+12 = 17 {pokemon_1[1]+pokemon_2[3]}, -1+7 = 6 {pokemon_1[2]+pokemon_2[2]}, None(0)+27 = 27 {pokemon_1[3]+pokemon_2[1]}, None(0)+2 = 2 {pokemon_1[4]+pokemon_2[0]} Sample Input / Driver Code: pokemon_1: [12, 3, 25, 1, None] pokemon_2: [5, -9, 3, None, None] #Function Call: print(mergeLineup(pokemon_1, pokemon_2)) Sample Output: [12, 3, 28, -8, 5] Balance Your Salami: Suppose the elements of an array ‘salami’ containing positive integers, denote the amount of Salami you got from each elder in Eid. Everyone gave you a single note of taka. Now your mother orders you to distribute the Salami between your younger sibling and you. Being a lazy person, you do not want to split any note into changes. So, you want to distribute the notes in such a way that for some index 0 < i < A.length – 1, you get all the notes starting from A[0], A[1], up to A[ i – 1]. And all the notes starting from A[ i ] up to A[ A.length – 1] will be given to your sibling. Thus, both of you get equal amounts. If such a distribution is possible, return true. Else, return false. Sample Input / Driver Code: salami: [1, 1, 1, 2, 1] #Function Call: print(balanceSalami(salami)) Sample Output: True Explanation: summation of [1, 1, 1] = summation of [2,1]. So you get three 1 taka notes and your sibling gets one 2 taka & one 1 taka note Sample Input / Driver Code: salami: [2, 1, 1, 2, 1] #Function Call: print(balanceSalami(salami)) Sample Output: False Sample Input / Driver Code: salami: [10, 3, 1, 2, 10] #Function Call: print(balanceSalami(salami)) Sample Output: True Explanation: summation of [10, 3] = summation of [1,2,10]. Protect Salami: On the night of Eid day, your mother gently tells you and your sibling, “You will lose your Salami money. Give them to me, I will keep them safe.” However, both of you now know your mother’s trick and are quite adamant to keep some money for yourselves this time. So, after brainstorming, you get an idea. You told your mother “Both of us got some repeated taka notes, i.e. these taka notes have appeared more than once. You can only take those repeated notes if there are at least two notes with the same number of repetition.” Implement the scenario using a proper method which takes the taka notes you both got as Salami as an array; and returns True if mother can take money. Otherwise returns False. Sample Input / Driver Code: salami: [4,5,6,6,4,3,6,4] #Function Call: print(protectSalami(salami)) Sample Output: True Explanation: Two notes repeat in this array: 4 and 6. 4 has a repetition of 3, 6 has a repetition of 3. Since two notes have the same repetition, mother can take money and the output is True. Sample Input / Driver Code: salami: [3,4,6,3,4,7,4,6,8,6,6] #Function Call: print(protectSalami(salami)) Sample Output: False Explanation: Three notes repeat in this array:3,4 and 6 .3 has a repetition of 2, 4 has a repetition of 3, 6 has a repetition of 4. Since no two notes have the same repetition output is False and mother cannot take money.BONUSUNGRADEDTASK Odd Even Wave: Write a method that takes an array as a parameter, and creates a new array that stores an odd even wave of the array. An odd even wave is when the adjacent elements of an odd number are even and the adjacent elements of the even numbers are odd. The first element of the resultant array will be the first element of the original array. It is guaranteed that the given array will have no extra odd or even numbers left. Sample Input / Driver Code: arr: [2,12,3,8,1,5] #Function Call: print(waveYourFlag(arr)) Sample Output: [2,3,12,1,8,5] Sample Input / Driver Code: arr: [45,23,78,84,41] #Function Call: print(waveYourFlag(arr)) Sample Output: [45,78,23,84,41]

$25.00 View

[SOLVED] Cse111 –

Course Title: Programming Language II Course Code: CSE111 Lab Assignment no: 8 Let’s Play with Numbers!!! Write the ComplexNumber class so that the following code generates the output below. class RealNumber: def __init__(self, r=0): self.__realValue = r def getRealValue(self): return self.__realValue def setRealValue(self, r): self.__realValue = r def __str__(self): return ‘RealPart: ‘+str(self.getRealValue()) cn1 = ComplexNumber() print(cn1) print(‘———‘) cn2 = ComplexNumber(5,7) print(cn2) OUTPUT: RealPart: 1.0 ImaginaryPart: 1.0 ——————– RealPart: 5.0 ImaginaryPart: 7.0 Write the ComplexNumber class so that the following code generates the output below. class RealNumber: def __init__(self, number=0): self.number = number def __add__(self, anotherRealNumber): return self.number + anotherRealNumber.number def __sub__(self, anotherRealNumber): return self.number – anotherRealNumber.number def __str__(self): return str(self.number)r1 = RealNumber(3) r2 = RealNumber(5) print(r1+r2) cn1 = ComplexNumber(2, 1) print(cn1) cn2 = ComplexNumber(r1, 5) print(cn2) cn3 = cn1 + cn2 print(cn3) cn4 = cn1 – cn2 print(cn4) OUTPUT: 8 2 + 1i 3 + 5i 5 + 6i -1 – 4i Write the CheckingAccount class so that the following code generates the output below: class Account: def __init__(self, balance): self._balance = balance def getBalance(self): return self._balance print(‘Number of Checking Accounts: ‘, CheckingAccount.numberOfAccount) print(CheckingAccount()) print(CheckingAccount(100.00)) print(CheckingAccount(200.00)) print(‘Number of Checking Accounts: ‘, CheckingAccount.numberOfAccount) OUTPUT: Number of Checking Accounts: 0 Account Balance: 0.0 Account Balance: 100.00 Account Balance: 200.00 Number of Checking Accounts: 3Write the Mango and the Jackfruit classes so that the following code generates the output below: class Fruit: def __init__(self, formalin=False, name=”): self.__formalin = formalin self.name = name def getName(self): return self.name def hasFormalin(self): return self.__formalin class testFruit: def test(self, f): print(‘—-Printing Detail—-‘) if f.hasFormalin(): print(‘Do not eat the’,f.getName(),’.’) print(f) else: print(‘Eat the’,f.getName(),’.’) print(f) m = Mango() j = Jackfruit() t1 = testFruit() t1.test(m) t1.test(j) OUTPUT: —-Printing Detail—– Do not eat the Mango. Mangos are bad for you —-Printing Detail—– Eat the Jackfruit. Jackfruits are good for you Write the ScienceExam class so that the following code generates the output below: class Exam: def examSyllabus(self): return “Maths , English” def examParts(self): return “Part 1 – Maths Part 2 – English ” engineering = ScienceExam(100,90,”Physics”,”HigherMaths”) print(engineering) print(‘———————————-‘) print(engineering.examSyllabus()) print(engineering.examParts()) print(‘==================================’) architecture = ScienceExam(100,120,”Physics”,”HigherMaths”,”Drawing”) print(architecture) print(‘———————————-‘) print(architecture.examSyllabus()) print(architecture.examParts()) OUTPUT: Parts: 4 ———————————- Maths , English , Physics , HigherMaths Part 1 – Maths Part 2 – English Part 3 – Physics Part 4 – HigherMaths ================================== Parts: 5 ———————————- Maths , English , Physics , HigherMaths , Drawing Part 1 – Maths Part 2 – English Part 3 – Physics Part 4 – HigherMaths Part 5 – Drawing Given the following class, write the code for the Sphere and the Cylinder class so that the following output is printed. class Shape3D: pi = 3.14159 def __init__(self, name = ‘Default’, radius = 0): self._area = 0 self._name = name self._height = ‘No need’ self._radius = radius def calc_surface_area(self): return 2 * Shape3D.pi * self._radius def __str__(self): return “Radius: “+str(self._radius) sph = Sphere(‘Sphere’, 5) print(‘———————————-‘) sph.calc_surface_area() print(sph) print(‘==================================’) cyl = Cylinder(‘Cylinder’, 5, 10) print(‘———————————-‘) cyl.calc_surface_area() print(cyl) OUTPUT: Shape name: Sphere, Area Formula: 4 * pi * r * r ———————————- Radius: 5, Height: No need Area: 314.159 ================================== Shape name: Cylinder, Area Formula: 2 * pi * r * (r + h) ———————————- Radius: 5, Height: 10 Area: 471.2385 Write the PokemonExtra class so that the following code generates the output below: class PokemonBasic: def __init__(self, name = ‘Default’, hp = 0, weakness = ‘None’, type = ‘Unknown’): self.name = name self.hit_point = hp self.weakness = weakness self.type = type def get_type(self): return ‘Main type: ‘ + self.type def get_move(self): return ‘Basic move: ‘ + ‘Quick Attack’ def __str__(self): return “Name: ” + self.name + “, HP: ” + str(self.hit_point) + “, Weakness: ” + self.weakness print(‘ ————Basic Info:————–‘) pk = PokemonBasic() print(pk) print(pk.get_type()) print(pk.get_move()) print(‘ ————Pokemon 1 Info:————-‘) charmander = PokemonExtra(‘Charmander’, 39, ‘Water’, ‘Fire’) print(charmander) print(charmander.get_type()) print(charmander.get_move()) print(‘ ————Pokemon 2 Info:————-‘) charizard = PokemonExtra(‘Charizard’, 78, ‘Water’, ‘Fire’, ‘Flying’, (‘Fire Spin’, ‘Fire Blaze’)) print(charizard) print(charizard.get_type()) print(charizard.get_move()) OUTPUT: ————Basic Info:————– Name: Default, HP: 0, Weakness: None Main type: Unknown Basic move: Quick Attack ————Pokemon 1 Info:————– Name: Charmander, HP: 39, Weakness: Water Main type: Fire Basic move: Quick Attack ————Pokemon 2 Info:————– Name: Charizard, HP: 78, Weakness: Water Main type: Fire, Secondary type: Flying Basic move: Quick Attack Other move: Fire Spin, Fire Blazedesign of the FootBallTeam and the CricketTeam classes that inherit from Team class so that the following code generates the output below: Driver Code Output class Team: def __init__(self, name): self.name = “default” self.total_player = 5 def info(self) print(“We love sports”) # Write your code here. class Team_test: def check(self, tm): print(“=========================”) print(“Total Player: “, tm.total_player) tm.info() f = FootBallTeam(“Brazil”) c = CricketTeam(“Bangladesh”) test = Team_test() test.check(f) test.check(c) ========================= Total Player: 11 Our name is Brazil We play Football We love sports ========================= Total Player: 11 Our name is Bangladesh We play Cricket We love sportsdesign of the Pikachu and Charmander classes that are derived from the Pokemon class so that the following output is produced: Driver Code Output class Pokemon: def __init__(self, p): self.pokemon = p self.pokemon_type = “Needs to be set” self.pokemon_weakness = “Needs to be set” def kind(self): return self.pokemon_type def weakness(self): return self.pokemon_weakness def what_am_i(self): print(“I am a Pokemon.”) pk1 = Pikachu() print(“Pokemon:”, pk1.pokemon) print(“Type:”, pk1.kind()) print(“Weakness:”, pk1.weakness()) pk1.what_am_i() print(“========================”) c1 = Charmander() print(“Pokemon:”, c1.pokemon) print(“Type:”, c1.kind()) print(“Weakness:”, c1.weakness()) c1.what_am_i() Pokemon: Pikachu Type: Electric Weakness: Ground I am a Pokemon. I am Pikachu. ======================== Pokemon: Charmander Type: Fire Weakness: Water, Ground and Rock I am a Pokemon. I am Charmander.design of the CSE and EEE classes that are derived from the Department class so that the following output is produced: Driver Code Output class Department: def __init__(self, s): self.semester = s self.name = “Default” self.id = -1 def student_info(self): print(“Name:”, self.name) print(“ID:”, self.id) def courses(self, c1, c2, c3): print(“No courses Approved yet!”) s1 = CSE(“Rahim”, 16101328,”Spring2016″) s1.student_info() s1.courses(“CSE110”, “MAT110”, “ENG101”) print(“==================”) s2 = EEE(“Tanzim”, 18101326, “Spring2018”) s2.student_info() s2.courses(“Mat110”, “PHY111”, “ENG101”) print(“==================”) s3 = CSE(“Rudana”, 18101326, “Fall2017”) s3.student_info() s3.courses(“CSE111”, “PHY101”, “MAT120”) print(“==================”) s4 = EEE(“Zainab”, 19201623, “Summer2019”) s4.student_info() s4.courses(“EEE201”, “PHY112”, “MAT120″) Name: Rahim ID: 16101328 Courses Approved to this CSE student in Spring2016 semester : CSE110 MAT110 ENG101 ================== Name: Tanzim ID: 18101326 Courses Approved to this EEE student in Spring2018 semester: Mat110 PHY111 ENG101 ================== Name: Rudana ID: 18101326 Courses Approved to this CSE student in Fall2017 semester: CSE111 PHY101 MAT120 ================== Name: Zainab ID: 19201623 Courses Approved to this EEE student in Summer2019 semester: EEE201 PHY112 MAT1201 class A: 2 def __init__(self): 3 self.temp = 4 4 self.sum = 1 5 self.y = 2 6 self.y = self.temp – 2 7 self.sum = self.temp + 3 8 self.temp -= 2 9 def methodA(self, m, n): 10 x = 0 11 self.y = self.y + m + self.temp 12 self.temp += 1 13 x = x + 2 + n 14 self.sum = self.sum + x + self.y 15 print(x, self.y, self.sum) 16 17 class B(A): 18 def __init__(self, b=None): 19 super().__init__() 20 self.x = 1 21 self.sum = 2 22 if b == None: 23 self.y = self.temp + 3 24 self.sum = 3 + self.temp + 2 25 self.temp -= 1 26 else: 27 self.sum = b.sum 28 self.x = b.x 29 def methodB(self, m, n): 30 y = 0 31 y = y + self.y 32 self.x = y + 2 + self.temp 33 self.methodA(self.x, y) 34 self.sum = self.x + y + self.sum 35 print(self.x, y, self.sum) Write the output of the following code: a1 = A() b1 = B() b2 = B(b1) a1.methodA(1, 1) b1.methodA(1, 2) b2.methodB(3, 2) Output: x y sumTask – 12 1 class A: 2 temp = 4 3 def __init__(self): 4 self.sum = 0 5 self.y = 0 6 self.y = A.temp – 2 7 self.sum = A.temp + 1 8 A.temp -= 2 9 def methodA(self, m, n): 10 x = 0 11 self.y = self.y + m + (A.temp) 12 A.temp += 1 13 x = x + 1 + n 14 self.sum = self.sum + x + self.y 15 print(x, self.y, self.sum) 16 17 class B(A): 18 x = 0 19 def __init__(self,b=None): 20 super().__init__() 21 self.sum = 0 22 if b==None: 23 self.y = A.temp + 3 24 self.sum = 3 + A.temp + 2 25 A.temp -= 2 26 else: 27 self.sum = b.sum 28 B.x = b.x 29 b.methodB(2, 3) 30 def methodB(self, m, n): 31 y = 0 32 y = y + self.y 33 B.x = self.y + 2 + A.temp 34 self.methodA(B.x, y) 35 self.sum = B.x + y + self.sum 36 print(B.x, y, self.sum) Write the output of the following code: a1 = A() b1 = B() b2 = B(b1) b1.methodA(1, b2.methodB(3, 2) 2) Output: x y sumTask – 13 1 class A: 2 temp = 3 3 def __init__(self): 4 self.sum = 0 5 self.y = 0 6 self.y = A.temp – 1 7 self.sum = A.temp + 2 8 A.temp -= 2 9 10 def methodA(self, m, n): 11 x = 0 12 n[0] += 1 13 self.y = self.y + m + A.temp 14 A.temp += 1 15 x = x + 2 + n[0] 16 n[0] = self.sum + 2 17 print(f”{x} {self.y} {self.sum}”) 18 19 class B(A): 20 x = 1 21 def __init__(self, b = None): 22 super().__init__() 23 self.sum = 2 24 if b == None: 25 self.y = self.temp + 1 26 B.x = 3 + A.temp + self.x 27 A.temp -= 2 28 else: 29 self.sum = self.sum + self.sum 30 B.x = b.x + self.x 31 def methodB(self, m, n): 32 y = [0] 33 self.y = y[0] + self.y + m 34 B.x = self.y + 2 + self.temp – n 35 self.methodA(self.x, y) 36 self.sum = self.x + y[0] + self.sum 37 print(f”{self.x} {y[0]} {self.sum}”) Write the output of the following code: x = [23] a1 = A() b1 = B() b2 = B(b1) a1.methodA(1, x) b2.methodB(3, 2) a1.methodA(1, x) Output: x y sumTask – 14 1 class A: 2 temp = 7 3 def __init__(self): 4 self.sum, self.y = 0, 0 5 self.y = A.temp – 1 6 self.sum = A.temp + 2 7 A.temp -= 3 8 def methodA(self, m, n): 9 x = 4 10 n[0] += 1 11 self.y = self.y + m + A.temp 12 A.temp += 2 13 x = x + 3 + n[0] 14 n[0] = self.sum + 2 15 print(f”{x} {self.y} {self.sum}”) 16 def get_A_sum(self): 17 return self.sum 18 def update_A_y(self, val): 19 self.y = val 20 class B(A): 21 x = 2 22 def __init__(self, b = None): 23 super().__init__() 24 self.sum = 2 25 if b == None: 26 self.y = self.temp + 1 27 B.x = 4 + A.temp + self.x 28 A.temp -= 2 29 else: 30 self.sum = self.sum + self.get_A_sum() 31 B.x = b.x + self.x 32 def methodB(self, m, n): 33 y = [0] 34 self.update_A_y(y[0] + self.y + m) 35 B.x = self.y + 4 + self.temp – n 36 self.methodA(self.x, y) 37 self.sum = self.x + y[0] + self.get_A_sum() 38 print(f”{self.x} {y[0]} {self.sum}”) Write the output of the following code: x = [32] a1 = A() b1 = B() b2 = B(b1) a1.methodA(2, x) b2.methodB(2, 3) a1.methodA(3, x) Output: x y sum

$25.00 View

[SOLVED] Cse111 –

Course Title: Programming Language II Course Code: CSE 111 Lab Assignment no: 7 ** You are not allowed to change any of the code of the tasks ** Use Inheritance to solve all problems Task – 1 Given the following classes, write the code for the BBA_Student class so that the following output is printed: class Student: def __init__(self, name=’Just a student’, dept=’nothing’): self.__name = name self.__department = dept def set_department(self, dept): self.__department = dept def get_name(self): return self.__name def set_name(self,name): self.__name = name def __str__(self): return ‘Name: ‘+self.__name+’ Department: ‘+self.__department #write your code here print(BBA_Student()) print(BBA_Student(‘Humpty Dumpty’)) print(BBA_Student(‘Little Bo Peep’)) Output: Name: default Department: BBA Name: Humpty Dumpty Department: BBA Name: Little Bo Peep Department: BBA Task – 2 class Vehicle: def __init__(self): self.x = 0 self.y = 0 def moveUp(self): self.y += 1 def moveDown(self): self.y -= 1 def moveRight(self): self.x += 1 def moveLeft(self): self.x -= 1 def __str__(self): return ‘(‘+str(self.x)+’ , ‘+str(self.y)+’)’ #write your code here print(‘Part 1’) print(‘——‘) car = Vehicle() print(car) car.moveUp() print(car) car.moveLeft() print(car) car.moveDown() print(car) car.moveRight() print(car) print(‘——‘) print(‘Part 2’) print(‘——‘) car1 = Vehicle2010() print(car1) car1.moveLowerLeft() print(car1) car2 = Vehicle2010() car2.moveLeft() print(car1.equals(car2)) car2.moveDown() print(car1.equals(car2)) OUTPUT: Part 1 —–(0 , 0) (0 , 1) (-1 , 1) (-1 , 0) (0 , 0) —— Part 2 —–(0 , 0) (-1 , -1) False True A vehicle assumes that the whole world is a 2-dimensional graph paper. It maintains its x and y coordinates (both are integers). The vehicle gets manufactured (constructed) at (0, 0) coordinate. Subtasks: 1. Design a Vehicle2010 class which inherits movement methods from Vehicle and adds new methods called move UpperRight, UpperLeft, LowerRight, LowerLeft. Each of these diagonal move methods must re-use two inherited and appropriate move methods. 2. Write an “equals” method which tests if significant class properties are the same (in this case x and y). Note: All moves are 1 step. That means a single call to any move method changes value of either x or y or both by 1. Task – 3 Given the following classes, write the code for the Cricket_Tournament and the Tennis_Tournment class so that the following output is printed. class Tournament: def __init__(self,name=’Default’): self.__name = name def set_name(self,name): self.__name = name def get_name(self): return self.__name #write your code here ct1 = Cricket_Tournament() print(ct1.detail()) print(“———————–“) ct2 = Cricket_Tournament(“IPL”,10,”t20″) print(ct2.detail()) print(“———————–“) tt = Tennis_Tournament(“Roland Garros”,128) print(tt.detail()) OUTPUT: Cricket Tournament Name: Default Number of Teams: 0 Type: No type ———————– Cricket Tournament Name: IPL Number of Teams: 10 Type: t20 ———————– Tennis Tournament Name: Roland Garros Number of Players: 128Book and the CD class so that the following output is printed. class Product: def __init__(self,id, title, price): self.__id = id self.__title = title self.__price = price def get_id_title_price(self): return “ID: “+str(self.__id)+” Title:”+self.__title+ “Price: “+str(self.__price) #write your code here book = Book(1,”The Alchemist”,500,”97806″,”HarperCollins”) print(book.printDetail()) print(“———————–“) cd = CD(2,”Shotto”,300,”Warfaze”,50,”Hard Rock”) print(cd.printDetail()) OUTPUT: ID: 1 Title: The Alchemist Price: 500 ISBN: 97806 Publisher: HarperCollins ———————– ID: 2 Title: Shotto Price: 300 Band: Warfaze Duration: 50 minutes Genre: Hard RockDog and the Cat class so that the following output is printed. class Animal: def __init__(self,sound): self.__sound = sound def makeSound(self): return self.__sound class Printer: def printSound(self, a): print(a.makeSound()) #write your code here d1 = Dog(‘bark’) c1 = Cat(‘meow’) a1 = Animal(‘Animal does not make sound’) pr = Printer() pr.printSound(a1) pr.printSound(c1) pr.printSound(d1) OUTPUT: Animal does not make sound meow bark Triangle and the Trapezoid class so that the following output is printed. class Shape: def __init__(self, name=’Default’, height=0, base=0): self.area = 0 self.name = name self.height = height self.base = base def get_height_base(self): return “Height: “+str(self.height)+”,Base: “+str(self.base) #write your code here tri_default = triangle() tri_default.calcArea() print(tri_default.printDetail()) print(‘————————–‘) tri = triangle(‘Triangle’, 10, 5) tri.calcArea() print(tri.printDetail()) print(‘—————————‘) trap = trapezoid(‘Trapezoid’, 10, 6, 4) trap.calcArea() print(trap.printDetail()) OUTPUT: Shape name: Default Height: 0, Base: 0 Area: 0.0 ————————— Shape name: Triangle Height: 10, Base: 5 Area: 25.0 ————————— Shape name: Trapezoid Height: 10, Base: 6, Side_A: 4 Area: 50.0 Player and the Manager class so that the following output is printed. To calculate the match earning use the following formula: 1. Player: (total_goal * 1000) + (total_match * 10) 2. Manager: match_win * 1000 class SportsPerson: def __init__(self, team_name, name, role): self.__team = team_name self.__name = name self.role = role self.earning_per_match = 0 def get_name_team(self): return ‘Name: ‘+self.__name+’, Team Name: ‘ +self.__team #write your code here player_one = Player(‘Juventus’, ‘Ronaldo’, ‘Striker’, 25, 32) player_one.calculate_ratio() player_one.print_details() print(‘——————————————‘) manager_one = Manager(‘Real Madrid’, ‘Zidane’, ‘Manager’, 25) manager_one.print_details() OUTPUT: Name: Ronaldo, Team Name: Juventus Team Role: Striker Total Goal: 25, Total Played: 32 Goal Ratio: 0.78125 Match Earning: 25320K ———————————- Name: Zidane, Team Name: Real Madrid Team Role: Manager Total Win: 25 Match Earning: 25000K https://bout.eveneer.xyz/evaluation-form

$25.00 View

[SOLVED] Cse111 –

Course Title: Programming Language II Course Code: CSE 111 Lab Assignment no: 6 Write a Student class to get the desired output as shown below. 1. Create a Student class and a class variable called ID initialized with 0. 2. Create a constructor that takes 4 parameters: name, department, age and cgpa. 3. Write a showDetails() method to represent all the details of a Student 4. Write a class method from_String() that takes 1 parameter which includes name, department, age and cgpa all four attributes in string. #Write your code here for subtasks 1-6. s1 = Student(“Samin”, “CSE”, 21, 3.91) s1.showDetails() print(“———————–“) s2 = Student(“Fahim”, “ECE”, 21, 3.85) s2.showDetails() print(“———————–“) s3 = Student(“Tahura”, “EEE”, 22, 3.01) s3.showDetails() print(“———————–“) s4 = Student.from_String(“Sumaiya-BBA-23-3.96”) s4.showDetails() # Write the answer of subtask 5 here # Write the answer of subtask 6 here #You are not allowed to change the code above OUTPUT ID: 1 Name: Samin Department: CSE Age: 21 CGPA: 3.91 ———————-ID: 2 Name: Fahim Department: ECE Age: 21 CGPA: 3.85 ———————– ID: 3 Name: Tahura Department: EEE Age: 22 CGPA: 3.01 ———————– ID: 4 Name: Sumaiya Department: BBA Age: 23 CGPA: 3.96 5. Explain the difference between a class variable and an instance variable. Print your answer at the very end of your code. 6. What is the difference between an instance method and class method? Print your answer at the very end Write the Assassin class so that the given code provides the expected output. 1. Create Assassin class 2. Create 1 class variable 3. Create 1 class method titled ‘failureRate()’ 4. Create 1 class method titled ‘failurePercentage()’ 5. Maximum success_rate is 100 [You are not allowed to change the code below] # Write your code here john_wick = Assassin(‘John Wick’, 100) john_wick.printDetails() print(‘================================’) nagisa = Assassin.failureRate(“Nagisa”, 20) nagisa.printDetails() print(‘================================’) akabane = Assassin.failurePercentage(“Akabane”, “10%”) akabane.printDetails() Output: Name: John Wick Success rate: 100% Total number of Assassin: 1 ============================ Name: Nagisa Success rate: 80% Total number of Assassin: 2 ============================ Name: Akabane Success rate: 90% Total number of Assassin: 3 Implement the design of the Passenger class so that the following output is produced: The assumption is Bus base-fare is 450 taka. A passenger can carry upto 20 kg for free. 50 taka will be added if bag weight is between 21 and 50 kg. 100 taka will be added if bag weight is greater than 50 kg. [You are not allowed to change the code below] # Write your code here print(“Total Passenger:”, Passenger.count) p1 = Passenger(“Jack”) p1.set_bag_weight(90) p2 = Passenger(“Carol”) p2.set_bag_weight(10) p3 = Passenger(“Mike”) p3.set_bag_weight(25) print(“=========================”) p1.printDetail() print(“=========================”) p2.printDetail() print(“=========================”) p3.printDetail() print(“=========================”) print(“Total Passenger:”, Passenger.count) Output: Total Passenger: 0 ========================= Name: Jack Bus Fare: 550 taka ========================= Name: Carol Bus Fare: 450 taka ========================= Name: Mike Bus Fare: 500 taka ========================= Total Passenger: 3 Implement the design of the Travel class so that the following output is produced: [You are not allowed to change the code below] # Write your code hereprint(“No. of Traveller =”, Travel.count) print(“=======================”) t1 = Travel(“Dhaka”,”India”) print(t1.display_travel_info()) print(“=======================”) t2 = Travel(“Kuala Lampur”,”Dhaka”) t2.set_time(23) print(t2.display_travel_info()) print(“=======================”) t3 = Travel(“Dhaka”,”New_Zealand”) t3.set_time(15) t3.set_destination(“Germany”) print(t3.display_travel_info()) print(“=======================”) t4 = Travel(“Dhaka”,”India”) t4.set_time(9) t4.set_source(“Malaysia”) t4.set_destination(“Canada”) print(t4.display_travel_info()) print(“=======================”) print(“No. of Traveller =”, Travel.count) Output No. of Traveller = 0 ======================= Source: Dhaka Destination:India Flight Time:1:00 ======================= Source: Kuala Lampur Destination:Dhaka Flight Time:23:00 ======================= Source: Dhaka Destination:Germany Flight Time:15:00 ======================= Source: Malaysia Destination:Canada Flight Time:9:00 ======================= No of Traveller = 4 Create an Employee Class that will have ● Two instance variable: name and workingPeriod ● A class method named employeeByJoiningYear(): o To create an Employee object by joining year for calculating the working period o It will have two Parameter name and year ● A static method experienceCheck() to check if an Employee is experienced or not o It will take working period and gender as parameter o If an employee’s working period is less than 3, he or she is not experienced [You are not allowed to change the code below] # Write your code here employee1 = Employee(‘Dororo’, 3) 3 6 Dororo Harry He is not experienced She is experienced Task 6 Implement the design of the Laptop class so that the following output is produced [You are not allowed to change the code below] # Write your code here lenovo = Laptop(“Lenovo”, 5); dell = Laptop(“Dell”, 7); print(lenovo.name, lenovo.count) print(dell.name, dell.count) print(“Total number of Laptops”, Laptop.laptopCount) Laptop.advantage() Laptop.resetCount() print(“Total number of Laptops”, Laptop.laptopCount) Output Lenovo 5 Dell 7 Total number of Laptops 12 Laptops are portable Total number of Laptops 0Design Cat class for the following code to get the output as shown. You have already solved this problem in assignment 4 using constructor overloading. Now, solve this again but this time DO NOT USE CONSTRUCTOR OVERLOADING. Hint: You will have to use classmethods. [You are not allowed to change the code below] # Write your code here print(“Total number of cats:”, Cat.Number_of_cats) c1 = Cat.no_parameter() c2 = Cat.first_parameter(“Black”) c3 = Cat(“Brown”, “jumping”) c4 = Cat(“Red”, “purring”) c5 = Cat.second_parameter(“playing”) print(“=======================”) c1.printCat() c2.printCat() c3.printCat() c4.printCat() c5.printCat() c1.changeColor(“Blue”) c3.changeColor(“Purple”) c1.printCat() c3.printCat() print(“=======================”) print(“Total number of cats:”, Cat.Number_of_cats) Output: Total number of cats: 0 ======================= White cat is sitting Black cat is sitting Brown cat is jumping Red cat is purring Grey cat is playing Blue cat is sitting Purple cat is jumping ======================= Total number of cats: 5 Write a Cylinder class to get the desired output as shown below. 1. You will have to create a Cylinder class. 2. You will have to create 2 class variables. 3. Create a required constructor. 4. Write 2 class methods: ● One that takes the height first and then the radius and then swaps # Write your code here c1 = Cylinder(0,0) Cylinder.area(c1.radius,c1.height) Cylinder.volume(c1.radius,c1.height) print(“===============================”) c2 = Cylinder.swap(8,3) c2.area(c2.radius,c2.height) c2.volume(c2.radius,c2.height) print(“===============================”) c3 = Cylinder.changeFormat(“7-13”) c3.area(c3.radius,c3.height) c3.volume(c3.radius,c3.height) print(“===============================”) Cylinder(0.3,5.56).area(Cylinder.radius,Cylinder.height) print(“===============================”) Cylinder(3,5).volume(Cylinder.radius,Cylinder.height) Output: Default radius=5 and height=18. Updated: radius=0 and height=0. Area: 0.0 Volume: 0.0 =============================== Default radius=0 and height=0. Updated: radius=3 and height=8. Area: 207.34511513692635 Volume: 226.1946710584651 =============================== Default radius=3 and height=8. Updated: radius=7.0 and height=13.0. Area: 879.645943005142 Volume: 2001.1945203366981 =============================== Default radius=7.0 and height=13.0. Updated: radius=0.3 and height=5.56. Area: 11.045839770021713 =============================== Default radius=0.3 and height=5.56. Updated: radius=3 and height=5. Volume: 141.3716694115407 ● One that takes a string where the radius and height values are separated with a hyphen. Write 2 static methods: ● One that calculates the area of a whole cylinder (formula: 2πr2 + 2πrh) ● Another that calculates the volume of a cylinder (formula: πr2h) **Observe the output values carefully to understand how the radius and height values are changing. [You are not allowed to change the code below] Write the Student class so that the given code provides the expected output. 1. Create Student class 2. Create 3 class variable 3. Create 1 class method for object creation 4. Create 1 class method for printing [You are not allowed to change the code below] # Write your code here Student.printDetails() print(‘#########################’) mikasa = Student(‘Mikasa Ackerman’, “CSE”) mikasa.individualDetail() print(‘——————————————‘) Student.printDetails() print(‘========================’) harry = Student.createStudent(‘Harry Potter’, “Defence Against Dark harry.individualDetail() print(‘——————————————-‘) Student.printDetails() print(‘=========================’) levi = Student.createStudent(“Levi Ackerman”, “CSE”) levi.individualDetail() print(‘——————————————–‘) Student.printDetails() Output: Total Student(s): 0 Other Institution Student(s): 0 ################################ Name: Mikasa Ackerman Department: CSE —————————————————–Total Student(s): 1 Other Institution Student(s): 0 =============================== Name: Harry Potter Department: Defence Against Dark Arts —————————————————–Total Student(s): 2 Other Institution Student(s): 1 =============================== Name: Levi Ackerman Department: CSE —————————————————–Total Student(s): 3 Other Institution Student(s): 1Write the SultansDine class so that the given code provides the expected output. [You are not allowed to change the code below] # Write your code here SultansDine.details() print(‘########################’) dhanmodi = SultansDine(‘Dhanmondi’) dhanmodi.sellQuantity(25) dhanmodi.branchInformation() print(‘—————————————–‘) SultansDine.details() print(‘========================’) baily_road = SultansDine(‘Baily Road’) baily_road.sellQuantity(15) baily_road.branchInformation() print(‘—————————————–‘) SultansDine.details() print(‘========================’) gulshan = SultansDine(‘Gulshan’) gulshan.sellQuantity(9) gulshan.branchInformation() print(‘—————————————–‘) SultansDine.details() Output: Total Number of branch(s): 0 Total Sell: 0 Taka ################################# Branch Name: Dhanmondi Branch Sell: 10000 Taka —————————————– Total Number of branch(s): 1 Total Sell: 10000 Taka Branch Name: Dhanmondi, Branch Sell: 10000 Taka Branch consists of total sell’s: 100.00% ================================ Branch Name: Baily Road Branch Sell: 5250 Taka —————————————– Total Number of branch(s): 2 Total Sell: 15250 Taka Branch Name: Dhanmondi, Branch Sell: 10000 Taka Branch consists of total sell’s: 65.57% Branch Name: Baily Road, Branch Sell: 5250 Taka Branch consists of total sell’s: 34.43% ================================ Branch Name: Gulshan Branch Sell: 2700 Taka —————————————– Total Number of branch(s): 3 Total Sell: 17950 Taka Branch Name: Dhanmondi, Branch Sell: 10000 Taka Branch consists of total sell’s: 55.71% Branch Name: Baily Road, Branch Sell: 5250 Taka Branch consists of total sell’s: 29.25% Branch Name: Gulshan, Branch Sell: 2700 Taka Branch consists of total sell’s: 15.04% Subtaks: 1. Create SultansDine class 2. Create 2 class variable and 1 class list 3. Create 1 class method 4. Calculation of branch sell is given below a. If sellQuantity < 10: i. Branch_sell = quantity * 300 b. Else if sellQuantity < 20: i. Branch_sell = quantity * 350 c. Else i. Branch_sell = quantity * 400 5. Calculation of branch’s sell percentage = (branch’s sell / total sell) * 100 Task 11 1 class Puzzle: 2 x = 0 3 def methodA(self): 4 Puzzle.x = 5 5 z = Puzzle.x + self.methodB(Puzzle.x) 6 print(Puzzle.x, z) 7 z = self.methodB(z + 2) + Puzzle.x 8 print(Puzzle.x, z) 9 self.methodB(Puzzle.x, z) 10 print(Puzzle.x, z) 11 def methodB(self, *args): 12 if len(args) == 1: 13 y = args[0] 14 Puzzle.x = y + Puzzle.x 15 print(Puzzle.x, y) 16 return Puzzle.x + 3 17 else: 18 z, x = args 19 z = z + 1 20 x = x + 1 21 print(z, x) p = Puzzle() Output-1 Output-2 p.methodA() p.methodA() p = Puzzle() p.methodA() p.methodB(7)Task 12 1 class FinalT6A: 2 temp = 3 3 4 def __init__(self, x, p): 5 self.sum, self.y = 0, 2 6 FinalT6A.temp += 3 7 self.y = self.temp – p 8 self.sum = self.temp + x 9 print(x, self.y, self.sum) 10 11 def methodA(self): 12 x, y = 0, 0 13 y = y + self.y 14 x = self.y + 2 + self.temp 15 self.sum = x + y + self.methodB(self.temp, y) 16 print(x, y, self.sum) 17 18 def methodB(self, temp, n):19 x = 0 20 FinalT6A.temp += 1 21 self.y = self.y + (FinalT6A.temp) 22 FinalT6A.temp -= 1 23 x = x + 2 + n 24 self.sum = self.sum + x + self.y 25 print(x, self.y, self.sum) 26 return self.sum q1 = FinalT6A(2,1) q1.methodA() q1.methodA() x y sumTask 13 1 class A: 2 temp = 4 3 def __init__(self): 4 self.y = self.temp – 2 5 self.sum = self.temp + 1 6 A.temp -= 2 7 self.methodA(3, 4) 8 def methodA(self, m, n): 9 x = 0 10 self.y = self.y + m + (self.temp) 11 A.temp += 1 12 x = x + 1 + n 13 self.sum = self.sum + x + self.y 14 print(x, self.y, self.sum) 15 16 class B: 17 x = 0 18 def __init__(self, b = None): 19 self.y, self.temp, self.sum = 5, -5, 2 20 21 if b == None: 22 self.y = self.temp + 323 self.sum = 3 + self.temp + 2 24 self.temp -= 2 25 else: 26 self.sum = b.sum 27 B.x = b.x 28 b.methodB(2, 3) 29 def methodA(self, m, n): 30 x = 2 31 self.y = self.y + m + (self.temp) 32 self.temp += 1 33 x = x + 5 + n 34 self.sum = self.sum + x + self.y 35 print(x, self.y, self.sum) 36 def methodB(self, m, n): 37 y = 0 38 y = y + self.y 39 B.x = self.y + 2 + self.temp 40 self.methodA(self.x, y) 41 self.sum = self.x + y + self.sum 42 print(self.x, y, self.sum)Task 14 1 class msgClass: 2 def __init__(self): 3 self.content = 0 4 5 class Quiz3: 6 x = 0 7 def __init__(self, k = None): 8 self.sum, self.y = 0, 0 9 if k is None: 10 self.sum = 5 11 Quiz3.x = 2 12 self.y = 2 13 else: 14 self.sum = self.sum + k 15 self.y = 3 16 Quiz3.x += 2 17 def methodA(self): 18 x = 1 19 y = 1 20 msg = [None] 21 myMsg = msgClass() 22 myMsg.content = Quiz3.x23 msg[0] = myMsg 24 msg[0].content = self.y + myMsg.content 25 self.y = self.y + self.methodB(msg[0]) 26 y = self.methodB(msg[0]) + self.y 27 x = y + self.methodB(msg, msg[0]) 28 self.sum = x + y + msg[0].content 29 print(x, y, self.sum) 30 def methodB(self, *args): 31 if len(args) == 2: 32 mg2, mg1 = args 33 x = 2 34 self.y = self.y + mg2[0].content 35 mg2[0].content = self.y + mg1.content 36 x = x + 2 + mg1.content 37 self.sum = self.sum + x + self.y 38 mg1.content = self.sum – mg2[0].content 39 print(Quiz3.x, self.y, self.sum) 40 return self.sum 41 42 elif len(args) == 1: 43 mg1, = args 44 x = 1 45 y = 2 46 y = self.sum + mg1.content47 self.y = y + mg1.content 48 x = Quiz3.x + 5 + mg1.content 49 self.sum = self.sum + x + y 50 Quiz3.x = mg1.content + x + 3 51 print(x, y, self.sum) 52 return y a1 = Quiz3() a2 = Quiz3(5) msg = msgClass() a1.methodA() a2.methodB(msg) x y sum

$25.00 View

[SOLVED] Cse111 –

Course Title: Programming Language II Course Code: CSE 111 Lab Assignment no: 5 Write a class called Exam with a required constructor. Then perform the addition using operator overloading #Write your code here #Do not change the following lines of code Q1 = Exam(int(input(“Quiz 1 (out of 10): “))) Q2 = Exam(int(input(“Quiz 2 (out of 10): “))) Lab = Exam(int(input(“Lab (out of 30): “))) Quiz 1 (out of 10): 10 Quiz 2 (out of 10): 10 Lab (out of 30): 30 Mid (out of 20): 20 Final (out of 30): 30 Sample Input 2: Quiz 1 (out of 10): 10 Quiz 2 (out of 10): 8 Lab (out of 30): 30 Mid (out of 20): 20 Final (out of 30): 29 Sample Output 2: Design the program to get the output as shown. Subtasks: 1. You will need to create 2 classes: Teacher and Course 2. Make all the variables in the Teacher class private. 3. Make all the variables in the Course class public. 4. Write the required codes in the Teacher and Course classes. [You are not allowed to change the code below] # Write your code here for subtasks 1-4 t1 = Teacher(“Saad Abdullah”, “CSE”) t2 = Teacher(“Mumit Khan”, “CSE”) t3 = Teacher(“Sadia Kazi”, “CSE”) c1 = Course(“CSE 110 Programming Language I”) c2 = Course(“CSE 111 Programming Language-II”) c3 = Course(“CSE 220 Data Structures”) c4 = Course(“CSE 221 Algorithms”) c5 = Course(“CCSE 230 Discrete Mathematics”) c6 = Course(“CSE 310 Object Oriented Programming”) c7 = Course(“CSE 320 Data Communications”) c8 = Course(“CSE 340 Computer Architecture”) t1.addCourse(c1) t1.addCourse(c2) t2.addCourse(c3) t2.addCourse(c4) t2.addCourse(c5) t3.addCourse(c6) t3.addCourse(c7) t3.addCourse(c8) t1.printDetail() t2.printDetail() t3.printDetail() Output: ==================================== Name: Saad Abdullah Department: CSE List of courses ==================================== CSE 110 Programming Language I CSE 111 Programming Language-II ==================================== ==================================== Name: Mumit Khan Department: CSE List of courses ==================================== CSE 220 Data Structures CSE 221 Algorithms CSE 230 Discrete Mathematics ==================================== ==================================== Name: Sadia Kazi Department: CSE List of courses ==================================== CSE 310 Object Oriented Programming CSE 320 Data Communications CSE 340 Computer Architecture ==================================== Design the program to get the output as shown. Subtasks: 1. You will need to create 2 classes: Team and Player 2. Make all the variables in the Team class private. 3. Make all the variables in the Player class public. 4. Write the required codes in the Team and Player classes Hints: ● Create a list in team class to store the player’s name in that list ● Use constructor overloading technique for Team class [You are not allowed to change the code below] # Write your code here for subtasks 1-4 b = Team() b.setName(‘Bangladesh’) mashrafi = Player(“Mashrafi”) b.addPlayer(mashrafi) tamim = Player(“Tamim”) b.addPlayer(tamim) b.printDetail() a = Team(“Australia”) ponting = Player(“Ponting”) a.addPlayer(ponting) lee = Player(“Lee”) a.addPlayer(lee) a.printDetail() Output: ===================== Team: Bangladesh List of Players: [‘Mashrafi’, ‘Tamim’] ===================== ===================== Team: Australia List of Players: [‘Ponting’, ‘Lee’] ===================== Look at the code and the sample inputs and outputs below to design the program accordingly. 1. Write a class called Color that only adds the 3 primary colors (red, blue and yellow). 2. Write a required constructor for the class. 3. You have to use operator overloading to get the desired outputs as shown. Hint: There will be only one constructor and only one method tackling the addition operation. No other methods are required. Note: Order of the color given as input should not matter. For example, in sample input 1, if the first input was yellow and then red, the output would still be orange. #Write your code here #Do not change the following lines of codeC1 = Color(input(“First Color: “).lower()) C2 = Color(input(“Second Color: “).lower()) C3 = C1 + C2 print(“Color formed:”, C3.clr) Sample Input 1: First Color: red Second Color: yellow Sample Output 1: Color formed: Orange Sample Input 2: First Color: red Second Color: blue Sample Output 2: Color formed: Violet Sample Input 3: First Color: yellow Second Color: BLUE Sample Output 3: Color formed: Green Write a class called Circle with the required constructor and methods to get the following output. Subtasks: 1. Create a class called Circle. 2. Create the required constructor. Use Encapsulation to protect the variables. [Hint: Assign the variables in private] 3. Create getRadius() and setRadius() method to access variables. 4. Create a method called area to calculate the area of circles. 5. Handle the operator overloading by using a special method to calculate the radius and area of circle 3. [You are not allowed to change the code below] # Write your code here for subtasks 1-5 c1 = Circle(4) print(“First circle radius:” , c1.getRadius()) print(“First circle area:” , c1.area()) c2 = Circle(5) print(“Second circle radius:” , c2.getRadius()) print(“Second circle area:” , c2.area()) c3 = c1 + c2 print(“Third circle radius:” , c3.getRadius()) print(“Third circle area:” , c3.area()) Output: First circle radius: 4 First circle area: 50.26548245743669 Second circle radius: 5 Second circle area: 78.53981633974483 Third circle radius: 9 Third circle area: 254.46900494077323 Write a class called Triangle with the required constructor and methods to get the following output. Subtasks: 1. Create a class called Triangle. 2. Create the required constructor. Use Encapsulation to protect the variables. [Hint: Assign the variables in private] 3. Create getBase(), getHeight(), setBase() and setHeight() methods to access variables. 4. Create a method called area to calculate the area of triangles. 5. Handle the operator overloading by using a special method to calculate the radius and area of triangle 3. [You are not allowed to change the code below] # Write your code here for subtasks 1-5 t1 = Triangle(10, 5) print(“First Triangle Base:” , t1.getBase()) print(“First Triangle Height:” , t1.getHeight()) print(“First Triangle area:” ,t1.area()) t2 = Triangle(5, 3) print(“Second Triangle Base:” , t2.getBase()) print(“Second Triangle Height:” , t2.getHeight()) print(“Second Triangle area:” ,t2.area()) t3 = t1 – t2 print(“Third Triangle Base:” , t3.getBase()) print(“Third Triangle Height:” , t3.getHeight()) print(“Third Triangle area:” ,t3.area()) Output: First Triangle Base: 10 First Triangle Height: 5 First Triangle area: 25.0 Second Triangle Base: 5 Second Triangle Height: 3 Second Triangle area: 7.5 Third Triangle Base: 5 Third Triangle Height: 2 Third Triangle area: 5.0 Observe the given code carefully. Try to understand from the given code and the outputs what to write in your class Dolls. # Write your code here obj_1 = Dolls(“Tweety”, 2500) print(obj_1.detail()) if obj_1 > obj_1: print(“Congratulations! You get the Tweety as a gift!”) else: print(“Thank you!”) print(“=========================”) obj_2 = Dolls(“Daffy Duck”, 1800) print(obj_2.detail()) if obj_2 > obj_1: print(“Congratulations! You get the Tweety as a gift!”) else: print(“Thank you!”) print(“=========================”) obj_3 = Dolls(“Bugs Bunny”, 3000) print(obj_3.detail()) if obj_3 > obj_1: print(“Congratulations! You get the Tweety as a gift!”) else: print(“Thank you!”) print(“=========================”) obj_4 = Dolls(“Porky Pig”, 1500) print(obj_4.detail()) if obj_4 > obj_1: print(“Congratulations! You get the Tweety as a gift!”) else: print(“Thank you!”) print(“=========================”) obj_5 = obj_2 + obj_3 print(obj_5.detail()) if obj_5 > obj_1: print(“Congratulations! You get the Tweety as a gift!”) else: print(“Thank you!”) Output: Doll: Tweety Total Price: 2500 taka Thank you! ========================= Doll: Daffy Duck Total Price: 1800 taka Thank you! ========================= Doll: Bugs Bunny Total Price: 3000 taka Congratulations! You get the Tweety as a gift! ========================= Doll: Porky Pig Total Price: 1500 taka Thank you! ========================= Dolls: Daffy Duck Bugs Bunny Total Price: 4800 taka Congratulations! You get the Tweety as a gift![You are not allowed to change the code above] Subtasks: 1. Create a Doll class. 2. Create the required constructor. 3. Write a method to print the name and the price of the object 4. Use operator overloading for the addition operators. 5. Write a method to handle operator overloading for the “>” logical operator that compares the price of the objects. Hints: ● Notice that the price of each object is being checked with the price of obj in the given code. ● Notice the word Doll in the first 4 outputs and the last output. You have to print exactly as represented here. Task 8 Design a class called Coordinates with an appropriate constructor. Then perform the subtraction, multiplication and equality check operations in the given code using operator overloading. #Write your code here #Do not change the following lines of code p1 = Coordinates(int(input()),int(input())) p2 = Coordinates(int(input()),int(input())) p4 = p1 – p2 print(p4.detail()) p5 = p1 * p2 print(p5.detail()) point_check = (p4 == p5) print(point_check) Sample Input 1: 1 2 3 4 Sample Output 1: (-2,-2) (3,8) The calculated coordinates are NOT the same. Sample Input 2: 0 0 0 0 Sample Output 2: (0,0) (0,0) The calculated coordinates are the same.

$25.00 View

[SOLVED] Cse111 –

Course Title: Programming Language II Course Code: CSE 111 Lab Assignment no: 3 & 4 Merged Patient class so that the following output is produced: [For BMI, the formula is BMI = weight/height^2, where weight is in kg and height in meters] Driver Code Output # Write your code here p1 = Patient(“A”, 55, 63.0, 158.0) p1.printDetails() print(“====================”) p2 = Patient(“B”, 53, 61.0, 149.0) p2.printDetails() Name: A Age: 55 Weight: 63.0 kg Height: 158.0 cm BMI: 25.236340330075304 ==================== Name: B Age: 53 Weight: 61.0 kg Height: 149.0 cm BMI: 27.476239809017613 Design a class Shape for the given code below. • Write a class Shape. • Write the required constructor that takes 3 parameters and initialize the instancevariables accordingly. • Write a method area() that prints the area. Hint: the area method can calxculate only for the shapes: Triangle, Rectangle, Rhombus, and Square. So, you have to use conditions inside this method For this task, assume that — ● for a triangle, the arguments passed are the base and height ● for a rhombus, the arguments passed are the diagonals ● for a square or rectangle, the arguments passed are the sides. Driver Code Output # Write your code here triangle = Shape(“Triangle”,10,25) triangle.area() print(“==========================”) square = Shape(“Square”,10,10) square.area() print(“==========================”) rhombus = Shape(“Rhombus”,18,25) rhombus.area() print(“==========================”) rectangle = Shape(“Rectangle”,15,30) rectangle.area() print(“==========================”) trapezium = Shape(“Trapezium”,15,30) trapezium.area() Area: 125.0 ========================== Area: 100 ========================== Area: 225.0 ========================== Area: 450 ========================== Area: Shape unknown Calculator class so that the following output is produced: Driver Code Output # Write your code here c1 = Calculator() print(“==================”) val = c1.calculate(10, 20, ‘+’) print(“Returned value:”, val) c1.showCalculation() print(“==================”) val = c1.calculate(val, 10, ‘-‘) print(“Returned value:”, val) c1.showCalculation() print(“==================”) val = c1.calculate(val, 5, ‘*’) print(“Returned value:”, val) c1.showCalculation() print(“==================”) val = c1.calculate(val, 16, ‘/’) print(“Returned value:”, val) c1.showCalculation() Calculator is ready! ================== Returned value: 30 10 + 20 = 30 ================== Returned value: 20 30 – 10 = 20 ================== Returned value: 100 20 * 5 = 100 ================== Returned value: 6.25 100 / 16 = 6.25 Design the Programmer class in such a way so that the following code provides the expected output. Hint: o Write the constructor with appropriate printing and multiple arguments. o Write the addExp() method with appropriate printing and argument. o Write the printDetails() method [You are not allowed to change the code below] # Write your code here. p1 = Programmer(“Ethen Hunt”, “Java”, 10) p1.printDetails() print(‘————————–‘) p2 = Programmer(“James Bond”, “C++”, 7) p2.printDetails() print(‘————————–‘) p3 = Programmer(“Jon Snow”, “Python”, 4) p3.printDetails() p3.addExp(5) p3.printDetails() OUTPUT: Horray! A new programmer is born Name: Ethen Hunt Language: Java Experience: 10 years. ————————– Horray! A new programmer is born Name: James Bond Language: C++ Experience: 7 years. ————————– Horray! A new programmer is born Name: Jon Snow Language: Python Experience: 4 years. Updating experience of Jon Snow Name: Jon Snow Language: Python Experience: 9 years. UberEats class so that the following output is produced: [For simplicity, you can assume that a customer will always order exact 2 items] Driver Code Output # Write your code here order1 = UberEats(“Shakib”, “01719658xxx”, “Mohakhali”) print(“=========================”) order1.add_items(“Burger”, “Coca Cola”, 220, 50) print(“=========================”) print(order1.print_order_detail()) print(“=========================”) order2 = UberEats (“Siam”, “01719659xxx”, “Uttara”) print(“=========================”) order2.add_items(“Pineapple”, “Dairy Milk”, 80, 70) print(“=========================”) print(order2.print_order_detail()) Shakib, welcome to UberEats! ========================= ========================= User details: Name: Shakib, Phone: 01719658xxx, Address: Mohakhali Orders: {‘Burger’: 220, ‘Coca Cola’: 50} Total Paid Amount: 270 ========================= Siam, welcome to UberEats! ========================= ========================= User details: Name: Siam, Phone: 01719659xxx, Address: Uttara Orders: {‘Pineapple’: 80, ‘Dairy Milk’: 70} Total Paid Amount: 150 Write a class called Customer with the required constructor and methods to get the following output. Subtasks: 1. Create a class called Customer. 2. Create the required constructor. 4. Create a method called purchase that can take as many arguments as the user wants to give. [You are not allowed to change the code below] # Write your codes for subtasks 1-4 here. customer_1 = Customer(“Sam”) customer_1.greet() customer_1.purchase(“chips”, “chocolate”, “orange juice”) print(“—————————–“) customer_2 = Customer(“David”) customer_2.greet(“David”) customer_2.purchase(“orange juice”) OUTPUT: Hello! Sam, you purchased 3 item(s): chips chocolate orange juice —————————– Hello David! David, you purchased 1 item(s): orange juiceAnalyze the given code below to write Cat class to get the output as shown. Hints: ● Remember, the constructor is a special method. Here, you have to deal with constructor overloading which is similar to method overloading. ● Your class should have 2 variables [You are not allowed to change the code below] #Write your code herec1 = Cat() c2 = Cat(“Black”) c3 = Cat(“Brown”, “jumping”) c4 = Cat(“Red”, “purring”) c1.printCat() c2.printCat() c3.printCat() c4.printCat() c1.changeColor(“Blue”) c3.changeColor(“Purple”) c1.printCat() c3.printCat() OUTPUT White cat is sitting Black cat is sitting Brown cat is jumping Red cat is purring Blue cat is sitting Purple cat is jumping Design the Student class such a way so that the following code provides the expected output. Hint: ● Write the constructor with appropriate default value for arguments. ● Write the dailyEffort() method with appropriate arguments. # Write your code here. harry = Student(‘Harry Potter’, 123) harry.dailyEffort(3) harry.printDetails() print(‘========================’) john = Student(“John Wick”, 456, “BBA”) john.dailyEffort(2) john.printDetails() print(‘========================’) naruto = Student(“Naruto Uzumaki”, 777, “Ninja”) naruto.dailyEffort(6) naruto.printDetails() OUTPUT: Name: Harry Potter ID: 123 Department: CSE Daily Effort: 3 hour(s) Suggestion: Keep up the good work! ======================== Name: John Wick ID: 456 Department: BBA Daily Effort: 2 hour(s) Suggestion: Should give more effort! ======================== Name: Naruto Uzumaki ID: 777 Department: Ninja Daily Effort: 6 hour(s) Suggestion: Excellent! Now motivate others. ● Write the printDetails() method. For printing suggestions check the following instructions. If hour

$25.00 View

[SOLVED] Cse111 –

Course Title: Programming Language II Course Code: CSE 111 Lab Assignment no: 2Question 1Write a class that for running the following codes: [You are not allowed to change the code below]#Write your class code here data_type1 = DataType(‘Integer’, 1234) print(data_type1.name) print(data_type1.value) print(‘=====================’) data_type2 = DataType(‘String’, ‘Hello’) print(data_type2.name) print(data_type2.value) print(‘=====================’) data_type3 = DataType(‘Float’, 4.0) print(data_type3.name) print(data_type3.value)Output:Integer 1234 ===================== String Hello ===================== Float 4.0Subtasks:1. Create a class named DataType with the required constructor. 2. Assign name and values in constructor according to the output.Question 2Design a class called Flower with the instance variables so that after executing the following line of code the desired result shown in the output box will be printed. [You are not allowed to change the code below]#Write your class code here flower1 = Flower() flower1.name=”Rose” flower1.color=”Red” flower1.num_of_petal=6 print(“Name of this flower:”, flower1.name) print(“Color of this flower:”,flower1.color) print(“Number of petal:”,flower1.num_of_petal) print(“=====================”) flower2 = Flower() flower2.name=”Orchid” flower2.color=”Purple” flower2.num_of_petal=4 print(“Name of this flower:”,flower2.name) print(“Color of this flower:”,flower2.color) print (“Number of petal:”,flower2. num_of_petal) #Write the code for subtask 2 and 3 here Output: Name of this flower: Rose Color of this flower: Red Number of petal: 6 ===================== Name of this flower: Orchid Color of this flower: Purple Number of petal: 4Subtask: 1) Design the class Flower with default constructor to get the above output. 2) At the end of the given code, also print the address of flower1 and flower2 objects. 3) Do they point to the same address? Print (‘they are same’ or ‘they are different’) at the very end to answer this question. Question 3Design a class Joker with parameterized constructor so that the following line of code prints the result shown in the output box. [You are not allowed to change the code below]#Write your class code here j1 = Joker(‘Heath Ledger’, ‘Mind Game’, False) print(j1.name) print(j1.power) print(j1.is_he_psycho) print(“=====================”) Output: Heath Ledger Mind Game False ===================== Joaquin Phoenix Laughing out Loud True ===================== different same j2 = Joker(‘Joaquin Phoenix’, ‘Laughing out Loud’, True) print(j2.name) print(j2.power) print(j2.is_he_psycho) print(“=====================”) if j1 == j2: print(‘same’) else: print(‘different’) j2.name = ‘Heath Ledger’ if j1.name == j2.name: print(‘same’) else: print(‘different’) #Write your code for 2,3 hereSubtask: 1) Design the class using a parameterized constructor. 2) The first if/else block prints the output as ‘different’, but why? Explain your answer and print your explanation at the very end. 3) The second if/else block prints the output as ‘same’, but why? Explain your answer and print your explanation at the very end. Question 4Design a class called Pokemon using a parameterized constructor so that after executing the following line of code the desired result shown in the output box will be printed. First object along with print has been done for you, you also need to create other objects and print accordingly to get the output correctly. [You are not allowed to change the code below]#Write your code for class hereteam_pika = Pokemon(‘pikachu’, ‘charmander’, 90, 60, 10) print(‘=======Team 1=======’) print(‘Pokemon 1:’,team_pika.pokemon1_name, team_pika.pokemon1_power) print(‘Pokemon 2:’,team_pika.pokemon2_name, team_pika.pokemon2_power) pika_combined_power = (team_pika.pokemon1_power + team_pika.pokemon2_power) * team_pika.damage_rate print(‘Combined Power:’, pika_combined_power) #Write your code for subtask 2,3,4 hereOutput: =======Team 1======= Pokemon 1: pikachu 90 Pokemon 2: charmander 60 Combined Power: 1500 =======Team 2======= Pokemon 1: bulbasaur 80 Pokemon 2: squirtle 70 Combined Power: 1350Subtask: 1) Design the Pokemon class using a parameterized constructor. The 5 values that are being passed through the constructor are pokemon 1 name, pokemon 2 name, pokemon 1 power, pokemon 2 power, damage rate respectively. After designing the class, if you run the above code the details in Team 1 will be printed. 2) Create an object named team_bulb and pass the value ‘bulbasaur’, ‘squirtle’, 80, 70, 9 respectively. 3) Use print statements accordingly to print the desired result of Team 2.Note: Power is always being calculated using the instance variables. Example: (team_pika.pokemon1_power + team_pika.pokemon2_power) * team_pika.damage_rateQuestion 5Design the Player class so that the code gives the expected output. [You are not allowed to change the code below]# Write Your Class Code Here player1 = Player() player1.name = “Ronaldo” player1.jersy_number = 9 player1.position = “Striker” print(“Name of the Player:”, player1.name) print(“Jersey Number of player:”, player1.jersy_number) print(“Position of player:”, player1.position) print(“===========================”) player2 = Player() player2.name = “Neuer” player2.jersy_number = 1 player2.position = “Goal Keeper” print(“Name of the player:”, player2.name) print(“Jersey Number of player:”, player2.jersy_number) print(“Position of player:”, player2.position)Output: Name of the Player: Ronaldo Jersy Number of player: 9 Position of player: Striker =========================== Name of the player: Neuer Jersy Number of player: 1 Position of player: Goal KeeperQuestion 6Design the Country class so that the code gives the expected output. [You are not allowed to change the code below]# Write your Class Code here country = Country() print(‘Name:’,country.name) print(‘Continent:’,country.continent) print(‘Capital:’,country.capital) print(‘Fifa Ranking:’,country.fifa_ranking) print(‘===================’) country.name = “Belgium” country.continent = “Europe” country.capital = “Brussels” country.fifa_ranking = 1 print(‘Name:’,country.name) print(‘Continent:’,country.continent) print(‘Capital:’,country.capital) print(‘Fifa Ranking:’,country.fifa_ranking)Output: Name: Bangladesh Continent: Asia Capital: Dhaka Fifa Ranking: 187 =================== Name: Belgium Continent: Europe Capital: Brussels Fifa Ranking: 1Question 7Write the DemonSlayer class so that the code gives the expected output. [You are not allowed to change the code below]# Write your Class Code here tanjiro = DemonSlayer(“Tanjiro”, “Water Breathing”, 10, 10) print(‘Name:’,tanjiro.name) print(‘Fighting Style:’,tanjiro.style) print(f’Knows {tanjiro.number_of_technique} technique(s) and has killed {tanjiro.kill} demon(s)’) print(‘===================’) zenitsu = DemonSlayer(“Zenitsu”, “Thunder Breathing”, 1, 4) print(‘Name:’,zenitsu.name) print(‘Fighting Style:’,zenitsu.style) print(f’Knows {zenitsu.number_of_technique} technique(s) and has killed {zenitsu.kill} demon(s)’) print(‘===================’) inosuke = DemonSlayer(“Inosuke”, “Beast Breathing”, 5, 7) print(‘Name:’,inosuke.name) print(‘Fighting Style:’,inosuke.style) print(f’Knows {inosuke.number_of_technique} technique(s) and has killed {inosuke.kill} demon(s)’) print(‘===================’) print(f'{tanjiro.name}, {zenitsu.name}, {inosuke.name} knows total {tanjiro.number_of_technique + zenitsu.number_of_technique + inosuke.number_of_technique} techniques’) print(f’They have killed total {tanjiro.kill + zenitsu.kill + inosuke.kill} demons’)Output: Name: Tanjiro Fighting Style: Water Breathing Knows 10 technique(s) and has killed 10 demon(s) =================== Name: Zenitsu Fighting Style: Thunder Breathing Knows 1 technique(s) and has killed 4 demon(s) =================== Name: Inosuke Fighting Style: Beast Breathing Knows 5 technique(s) and has killed 7 demon(s) =================== Tanjiro, Zenitsu, Inosuke knows total 16 techniques They have killed total 21 demonsQuestion 8Write the box class so that the code gives the expected output.#Write your class code hereprint(“Box 1”) b1 = box([10,10,10]) print(“=========================”) print(“Height:”, b1.height) print(“Width:”, b1.width) print(“Breadth:”, b1.breadth) print(“————————-“) print(“Box 2”) b2 = box((30,10,10)) print(“=========================”) print(“Height:”, b2.height) print(“Width:”, b2.width) print(“Breadth:”, b2.breadth) b2.height = 300 print(“Updating Box 2!”) print(“Height:”, b2.height) print(“Width:”, b2.width) print(“Breadth:”, b2.breadth) print(“————————-“) print(“Box 3”) b3 = b2 print(“Height:”, b3.height) print(“Width:”, b3.width) print(“Breadth:”, b3.breadth) Output: Box 1 Creating a Box! Volume of the box is 1000 cubic units. ========================= Height: 10 Width: 10 Breadth: 10 ——————————————— Box 2 Creating a Box! Volume of the box is 3000 cubic units. ========================= Height: 30 Width: 10 Breadth: 10 Updating Box 2! Height: 300 Width: 10 Breadth: 10 ——————————————— Box 3 Height: 300 Width: 10 Breadth: 10Question 9Design the required class from the given code and the outputs. [You are not allowed to change the code below]Hint: Number of the border characters for the top and the bottom = 1 + Number of spaces between the left side border and the first character of the button name + Length of the button name + Number of spaces between the right side border and the last character of the button name + 1NOTE: Don’t count the space or any character from the button representation to solve this problem.#Write your class code hereword = “CANCEL” spaces = 10 border = ‘x’ b1 = buttons(word, spaces, border) print(“=======================================================”) b2 = buttons(“Notify”,3, ‘!’) print(“=======================================================”) b3 = buttons(‘SAVE PROGRESS’, 5, ‘$’)Output:CANCEL Button Specifications: Button name: CANCEL Number of the border characters for the top and the bottom: 28 Number of spaces between the left side border and the first character of the button name: 10 Number of spaces between the right side border and the last character of the button name: 10 Characters representing the borders: xxxxxxxxxxxxxxxxxxxxxxxxxxxxx x CANCEL x xxxxxxxxxxxxxxxxxxxxxxxxxxxx ========================================================= Notify Button Specifications: Button name: Notify Number of the border characters for the top and the bottom: 14 Number of spaces between the left side border and the first character of the button name: 3 Number of spaces between the right side border and the last character of the button name: 3 Characters representing the borders: !!!!!!!!!!!!!!! ! Notify ! !!!!!!!!!!!!!! ========================================================= SAVE PROGRESS Button Specifications: Button name: SAVE PROGRESS Number of the border characters for the top and the bottom: 25 Number of spaces between the left side border and the first character of the button name: 5 Number of spaces between the right side border and the last character of the button name: 5 Characters representing the borders: $$$$$$$$$$$$$$$$$$$$$$$$$$ $ SAVE PROGRESS $ $$$$$$$$$$$$$$$$$$$$$$$$$A class has been designed for this question. Solve the questions to get the desired result as shown in the output box. [You are not allowed to change the code below]class Wadiya(): def __init__(self): self.name = ‘Aladeen’ self.designation = ‘President Prime Minister Admiral General’ self.num_of_wife = 100 self.dictator = True#Write your code for subtask 1, 2, 3 and 4 hereOutput:Part 1: Name of President: Aladeen Designation: President Prime Minister Admiral General Number of wife: 100 Is he/she a dictator: True Part 2: Name of President: Donald Trump Designation: President Number of wife: 1 Is he/she a dictator: FalseSubtask: 1) Create an object named wadiya. 2) Use the object to print the values as shown in part 1 (Also print the sentence Part 1) 3) Use the same object to change and print the values in part 2 (Also print the sentence Part 2) 4) Did changing the instance variable values using the same object, affect the previous values of Part 1? (Print ‘previous information lost’ or ‘No, changing had no effect on previous value’)Write the output of the following code:1 class Human: Output 2 def __init__(self): 3 self.age = 0 4 self.height = 0.0 5 6 h1 = Human() 7 h2 = Human() 8 h1.age = 21 9 h1.height = 5.5 10 print(h1.age) 11 print(h1.height) 12 h2.height = h1.height – 3 13 print(h2.height) 14 h2.age = h1.age 15 h1.age += h1.age 16 print(h1.age) 17 h2 = h1 18 print(h2.age) 19 print(h2.height) 20 h1.age += h1.age 21 h2.height += h2.height 22 print(h1.age) 23 print(h1.height) 24 h2.age += h2.age 25 h1.age = h2.age 26 print(h2.age)1 class Student: Output 2 def __init__(self): 3 self.name = None 4 self.cgpa = 0.0 5 s1 = Student() 6 s2 = Student() 7 s3 = None 8 s1.name = “Student One” 9 s1.cgpa = 2.3 10 s3 = s1 11 s2.name = “Student Two” 12 s2.cgpa = s3.cgpa + 1 13 s3.name = “New Student” 14 print(s1.name) 15 print(s2.name) 16 print(s3.name) 17 print(s1.cgpa) 18 print(s2.cgpa) 19 print(s3.cgpa) 20 s3 = s2 21 s1.name = “old student” 22 s2.name = “older student” 23 s3.name = “oldest student” 24 s2.cgpa = s1.cgpa – s3.cgpa + 4.5 25 print(s1.name) 26 print(s2.name) 27 print(s3.name) 28 print(s1.cgpa) 29 print(s2.cgpa) 30 print(s3.cgpa)Write the output of the following code:1 class Ninja: Output 2 def __init__(self): 3 self.rank = 0 4 self.stamina = 0.0 5 6 naruto = Ninja() 7 yellow_flash = Ninja() 8 naruto.rank = 1 9 naruto.stamina = 95.0 10 print(naruto.rank) 11 print(naruto.stamina) 12 yellow_flash.stamina = naruto.stamina – 2 13 print(yellow_flash.stamina) 14 yellow_flash.rank += (naruto.rank + 1) 15 print(yellow_flash.rank) 16 minato = yellow_flash 17 print(minato.rank) 18 print(minato.stamina) 19 naruto.rank = minato.rank – 1 20 naruto.stamina = yellow_flash.stamina + 3 21 print(naruto.rank) 22 print(naruto.stamina) 23 naruto.rank = -(-naruto.rank) 24 yellow_flash.stamina = -(-minato.stamina) 25 print(naruto.rank) 26 print(minato.stamina)

$25.00 View