All Flashcards
What does the following code output?
python
text = "Hello World"
print(text[6:])
World
What does the following code output?
python
text = "Programming"
print(text[:4])
Prog
What does the following code output?
python
str1 = "Hello"
str2 = "World"
print(str1 + " " + str2)
Hello World
What does the following code output?
python
word = "Python"
for i in range(len(word)):
print(word[i])
P y t h o n
What does the following code output?
python
text = "OpenAI"
print(text.lower())
openai
What does the following code output?
python
text = "Coding is fun!"
print(text.replace("fun", "awesome"))
Coding is awesome!
Identify the error in the following code:
python
if x = 5:
print("x is 5")
The assignment operator = should be the equality operator == in the if statement.
What does the following code output?
python
count = 0
while count < 3:
print(count)
count += 1
0 1 2
What does the following code output?
python
def greet(name):
print("Hello, " + name + "!")
greet("Alice")
Hello, Alice!
What does the following code output?
python
numbers = [1, 2, 3, 4, 5]
print(numbers[1:3])
[2, 3]
How is encryption applied in real-world scenarios?
Protecting sensitive data like passwords, credit card numbers, and personal information during online transactions.
How are algorithms applied in real-world scenarios?
Search engines use complex algorithms to rank search results, and social media platforms use algorithms to personalize content feeds.
How is data abstraction applied in real-world scenarios?
Using a car: you don't need to know how the engine works to drive it; you only need to know how to use the steering wheel, pedals, etc.
What is the significance of indexing in strings?
Allows access to specific characters within the string.
Explain the concept of immutability in the context of strings.
Strings in many languages (like Python) are immutable, meaning their values cannot be changed after creation. Operations create new strings.
How does the + operator work with strings?
It performs string concatenation, joining two strings together.
What is the role of booleans in control structures?
Booleans are used to determine which code block to execute in conditional statements (if/else).
What is the purpose of a for loop?
To repeat a block of code a specific number of times or over a sequence.
What is the purpose of a while loop?
To repeat a block of code as long as a condition is true.
What is the difference between parameters and arguments?
Parameters are placeholders in the function definition; arguments are the actual values passed when the function is called.
What are the characteristics of a good algorithm?
Precise, unambiguous, and finite.
Explain the concept of data abstraction.
Hiding the complex implementation details and showing only the essential information.
What is the purpose of DNS?
Translates domain names (e.g., google.com) to IP addresses.