Computer Science
Consider the following package
music/ Top-level package
├── __init__.py
├── formats/ Subpackage for file format
│ ├── __init__.py
│ └── wavread.py
│ └── wavwrite.py
│
├── effects/ Subpackage for sound effects
│ └── __init__.py
│ └── echo.py
│ └── surround.py
│ └── reverse.py
│
└── filters/ Subpackage for filters
├── __init__.py
└── equalizer.py
└── vocoder.py
└── karaoke.py
Each of the above modules contain functions play(), writefile() and readfile().
(a) If the module wavwrite is imported using command import music.formats.wavwrite. How will you invoke its writefile() function ? Write command for it.
(b) If the module wavwrite is imported using command from music.formats import wavwrite. How will you invoke its writefile() function ? Write command for it.
Answer
(a) If the module wavwrite is imported using the command import music.formats.wavwrite
, we can invoke its writefile() function by using the module name followed by the function name:
import music.formats.wavwrite
music.formats.wavwrite.writefile()
(b) If the module wavwrite is imported using the command from music.formats import wavwrite
, we can directly invoke its writefile() function without prefixing the module name:
from music.formats import wavwrite
writefile()
Related Questions
Consider the following code :
import random print(int(20 + random.random() * 5), end = ' ') print(int(20 + random.random() * 5), end = ' ') print(int(20 + random.random() * 5), end = ' ') print(int(20 + random.random() * 5))
Find the suggested output options 1 to 4. Also, write the least value and highest value that can be generated.
- 20 22 24 25
- 22 23 24 25
- 23 24 23 24
- 21 21 21 21
Consider the following code :
import random print(100 + random.randint(5, 10), end = ' ' ) print(100 + random.randint(5, 10), end = ' ' ) print(100 + random.randint(5, 10), end = ' ' ) print(100 + random.randint(5, 10))
Find the suggested output options 1 to 4. Also, write the least value and highest value that can be generated.
- 102 105 104 105
- 110 103 104 105
- 105 107 105 110
- 110 105 105 110
What are the possible outcome(s) executed from the following code ? Also specify the maximum and minimum values that can be assigned to variable PICK.
import random PICK = random.randint(0, 3) CITY = ["DELHI", "MUMBAI", "CHENNAI", "KOLKATA"]; for I in CITY : for J in range(1, PICK): print(I, end = " ") print()
- DELHIDELHI
MUMBAIMUMBAI
CHENNAICHENNAI
KOLKATAKOLKATA - DELHI
DELHIMUMBAI
DELHIMUMBAICHENNAI - DELHI
MUMBAI
CHENNAI
KOLKATA - DELHI
MUMBAIMUMBAI
KOLKATAKOLKATAKOLKATA
- DELHIDELHI
Write a Python program having following functions :
- A function with the following signature :
remove_letter(sentence, letter)
This function should take a string and a letter (as a single-character string) as arguments, returning a copy of that string with every instance of the indicated letter removed. For example, remove_letter("Hello there!", "e") should return the string "Hllo thr!".
Try implementing it using<str>.split()
function. - Write a function to do the following :
Try implementing the capwords() functionality using other functions, i.e., split(), capitalize() and join(). Compare the result with the capwords() function's result.
- A function with the following signature :