Python Answers

Questions answered by Experts: 5 288

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search

1: Define a function that takes an argument. Call the function. Identify what code is the argument and what code is the parameter

2: Call your function from Example 1 three times with different kinds of arguments: a value, a variable, and an expression. Identify which kind of argument is which. 


3: Create a function with a local variable. Show what happens when you try to use that variable outside the function. Explain the results.


4: Create a function that takes an argument. Give the function parameter a unique name. Show what happens when you try to use that parameter name outside the function. Explain the results.


5: Show what happens when a variable defined outside a function has the same name as a local variable inside a function. Explain what happens to the value of each variable as the program runs.


he volume of a sphere is 4/3πr3, where π has the value of "pi" given in Section 2.1 of your textbook. Write a function called print_volume (r) that takes an argument for the radius of the sphere, and prints the volume of the sphere.

Call your print_volume function three times with different values for radius.

Include all of the following in your Learning Journal:

  • The code for your print_volume function.
  • The inputs and outputs to three calls of your print_volume.

Note: This question is part 2 of question #295009 so please answer the take both questions as one question and then answer. please thank you.


c. Book class should include a constructor and the following methods: -  

 - setBookISBN: to set the ISBN for the book. (Hint: You can use ISBN class input method) 

- DisplayBookISBN: to get the ISBN of the book. (Hint: You can use ISBN class method) 

- display details: to display all the information of a book which includes Books ISBN, title, authorName, publisherName, Address (Country, City, Street Name and House Number) and price.  

 

Question 2: 

Create class diagram of Question-01. 


Question 1

a. Design a class called ISBN to represent an International Standard Book Number. The ISBN consists of 10 digits divided into 4 parts. For example, the ISBN 7 758871 47 5 represents the following information:  

 - The first part: The first digit "7" signifies the book is from a French-speaking country.  

- The second part: "758871" identifies the publisher.  

- The third part: "47" is the title number for the book.  

- The fourth part: "5" is a check digit to indicate that the sum of the ISBN digits is 10.  


The class should have a method to take input from the users and display it on the screen.  


b. Design a Book class that represents relevant information about a book, including the book's title, authorName, publisherName, Address (remember the class we created in Question-1 has a relationship) and price. Find out the relationship between Book and ISBN and code accordingly.  

 


Problem 3: A multi-graph is a graph which may have more than one edge (parallel edges) between a pair of vertices. Suppose that these graphs may also have self-loops (an edge from a vertex to itself). Given such a graph G as an input, print the adjacency list representation of an equivalent undirected graph G’, in which all the multiple edges between two vertices are replaced by a single edge, and all self-loops are removed. Your algorithm should run in O(n+m) time. Input Format: The input is a text file which gives the adjacency list representation of the multigraph. The first line specifies the number of vertices and edges n and m. The next m lines specify the m edges, one edge per line. Assume the vertices are numbered 0 to n-1.

Output Format: The adjacency list representation of the new graph G’.

Sample Input (for the graph above): 3 6

0 0

0 2

2 2

0 2

0 2

0 1

Sample Output: Adjacency list representation of G’: 0: 1 2 1: 0 2: 0


 Given an input undirected graph, create and print the adjacency list and adjacency matrix representations of the graph. Input Format: The input is a text file which describes an undirected graph. The first line of the file specifies n & m, the number of vertices and number of edges in the graph respectively. The next m lines specify the m edges of the graph, one line per edge. An edge is described by its end points. If the number of vertices is n, assume that the vertices of the graph are numbered (0,1,..n-1). Output Format: Print the adjacency list and adjacency matrix representation of the graph. In the adjacency list representation, for a given vertex, the order of its adjacent vertices does not matter.


Design a 'book' class with title, author,publisher, price and author's royalty as instance variables. Provide getter and setter properties for all variables. Also define a method royalty() to calculate royalty amount author can expect to receive the following royalties :10% of the retail price on the first 500 copies ;12.5% for the next, 1000 copies sold, then 15% for all further other copies sold


Half pyramid with numbers but the numbers printed from below like input 1and 3


Output will be


6


5 4


3 2 1

: A multi-graph is a graph which may have more than one edge (parallel edges) between a pair of vertices. Suppose that these graphs may also have self-loops (an edge from a vertex to itself). Given such a graph G as an input, print the adjacency list representation of an equivalent undirected graph G’, in which all the multiple edges between two vertices are replaced by a single edge, and all self-loops are removed. Your algorithm should run in O(n+m) time. Input Format: The input is a text file which gives the adjacency list representation of the multigraph. The first line specifies the number of vertices and edges n and m. The next m lines specify the m edges, one edge per line. Assume the vertices are numbered 0 to n-1. Output Format: The adjacency list representation of the new graph G’. Sample Input (for the graph above): 3 6 0 0 0 2 2 2 0 2 0 2 0 1 Sample Output: Adjacency list representation of G’: 0: 1 2 1: 0 2: 0


Given a directed graph in adjacency matrix form, determine if it contains a universal sink – a vertex with in-degree n-1 and out-degree 0. (The number of vertices in the graph is n.) Input Format: The input is a text file which gives the adjacency matrix representation of a directed graph. Sample Input (for the graph above): 0 1 1 1 0 0 0 1 0 0 0 1 0 0 0 0 Sample Output: Yes 


LATEST TUTORIALS
APPROVED BY CLIENTS