All Flashcards
What does RANDOM(1, 6) return in pseudocode?
A random integer between 1 and 6, inclusive.
What is the purpose of the following Python code?
python
import random
c = random.randint(a, b)
To generate a random integer between 'a' and 'b' (inclusive) and assign it to the variable 'c'.
Predict the output:
pseudocode
count ← 0
LOOP 5 TIMES
roll ← RANDOM(1, 2)
IF roll = 1
count ← count + 1
END IF
END LOOP
DISPLAY count
A number between 0 and 5, inclusive, representing the number of times 1 was rolled.
Complete the following Python code to generate a random number between 10 and 20:
python
import random
number = random.______(10, 20)
randint
What is the output of this code?
python
import random
random.seed(42)
print(random.randint(1, 10))
random.seed(42)
print(random.randint(1, 10))
The same number will be printed twice because the seed is set to the same value before each call to randint().
Identify the error:
python
import random
print(random.randInt(1, 10))
random.randInt should be random.randint. Python is case-sensitive.
Predict the output:
pseudocode
number ← RANDOM(1, 10)
DISPLAY number
A random integer between 1 and 10 (inclusive).
Complete the pseudocode to simulate rolling a die:
pseudocode
roll ← RANDOM(____, ____)
1, 6
What is the output of the following code?
python
import random
numbers = [1, 2, 3, 4, 5]
print(random.choice(numbers))
A random element from the list numbers (i.e., 1, 2, 3, 4, or 5).
What is the output of this code?
python
import random
random.seed(1)
print(random.random())
random.seed(1)
print(random.random())
The same random floating-point number between 0 and 1 will be printed twice.
How is random number generation applied in real-world scenarios?
Simulations, games, cryptography, and statistical sampling.
How is data visualization applied in real-world scenarios?
Business intelligence, scientific research, and public health monitoring.
How is cybersecurity applied in real-world scenarios?
Protecting financial transactions, securing personal data, and preventing cyber warfare.
How is the concept of variables used in a banking system?
Storing customer account balances, transaction amounts, and interest rates.
How are control structures used in traffic light systems?
To control the sequence and timing of traffic lights based on conditions (e.g., time of day, traffic volume).
How is HTML used in e-commerce websites?
To structure the content of product pages, shopping carts, and checkout forms.
How is data mining used in marketing?
To identify customer segments, predict purchasing behavior, and personalize marketing campaigns.
How is encryption used in online communication?
To protect the confidentiality of messages and data transmitted over the Internet.
How is the Internet used in education?
To provide access to online courses, research materials, and educational resources.
How is binary representation used in image processing?
Representing pixel color values for image storage, manipulation, and display.
What is sequence in programming?
Instructions are executed in order, one after the other.
What is selection in programming?
Code blocks are executed based on conditions (if, if-else).
What is iteration in programming?
Code blocks are repeated until a condition is met or for a specific number of times (loops).
What is the purpose of random number generation?
To introduce unpredictability and simulate real-world events in programs.
Describe the function of routers in the Internet.
Routers direct data packets between networks to ensure they reach their destination.
Explain the role of protocols in Internet communication.
Protocols are standard rules that enable computers to communicate with each other. Examples include TCP/IP, HTTP, and DNS.
What is data representation?
How data is encoded and stored in a computer system (e.g., binary, ASCII, Unicode).
What is data visualization?
Using charts and graphs to understand patterns in data.
What is data mining?
Discovering useful information from large datasets.
What is ethical computing?
Applying moral principles to the use of computers and technology, including privacy, avoiding bias, and respecting intellectual property.