Computer Science
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
Answer
105 107 105 110
110 105 105 110
The least value that can be generated is 105 and the highest value that can be generated is 110.
Explanation
print(100 + random.randint(5, 10), end=' ')
— This statement generates a random integer between 5 and 10, inclusive, and then adds 100 to it. So, the suggested outputs range from 105 to 110.
The lowest value that can be generated is 100 + 5 = 105.
The highest value that can be generated is 100 + 10 = 110.
Related Questions
What are the possible outcome(s) executed from the following code? Also specify the maximum and minimum values that can be assigned to variable NUMBER.
STRING = "CBSEONLINE" NUMBER = random.randint(0, 3) N = 9 while STRING[N] != 'L' : print(STRING[N] + STRING[NUMBER] + '#', end = '') NUMBER = NUMBER + 1 N = N - 1
- ES#NE#IO#
- LE#NO#ON#
- NS#IE#LO#
- EC#NB#IS#
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 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.
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