Podcast
Questions and Answers
Consider the following code snippet: x = 5; y = 10; if x > y: x, y = y, x; print(x, y)
. What will be the output of this code?
Consider the following code snippet: x = 5; y = 10; if x > y: x, y = y, x; print(x, y)
. What will be the output of this code?
Consider the following code snippet: x = [1, 2, 3, 4, 5]; if len(x) > 3: x = x[1:]; print(x)
. What will be the output of this code?
Consider the following code snippet: x = [1, 2, 3, 4, 5]; if len(x) > 3: x = x[1:]; print(x)
. What will be the output of this code?
What is the output of the code if a > 10 and b > 10: if a + b == 50: print("Sum is 50") else: print("Sum is not 50") else: print("One or both numbers are 10 or less")
?
What is the output of the code if a > 10 and b > 10: if a + b == 50: print("Sum is 50") else: print("Sum is not 50") else: print("One or both numbers are 10 or less")
?
What is the output of the code list = [10, 20, 30, 40, 50]; if list[:2] == [10, 20]: print("First two elements match.") else: print("Mismatch.")
?
What is the output of the code list = [10, 20, 30, 40, 50]; if list[:2] == [10, 20]: print("First two elements match.") else: print("Mismatch.")
?
Signup and view all the answers
What is the output of the loop for i in range(5): if i % 2 == 0: if i != 0: print(f"{i} is even and not zero.") else: print(f"{i} is odd.")
?
What is the output of the loop for i in range(5): if i % 2 == 0: if i != 0: print(f"{i} is even and not zero.") else: print(f"{i} is odd.")
?
Signup and view all the answers
What is the condition for printing "Sum is 50" in the code if a > 10 and b > 10: if a + b == 50: print("Sum is 50")
?
What is the condition for printing "Sum is 50" in the code if a > 10 and b > 10: if a + b == 50: print("Sum is 50")
?
Signup and view all the answers
In the code list = [10, 20, 30, 40, 50]; if list[:2] == [10, 20]: print("First two elements match.")
, what is the purpose of list[:2]
?
In the code list = [10, 20, 30, 40, 50]; if list[:2] == [10, 20]: print("First two elements match.")
, what is the purpose of list[:2]
?
Signup and view all the answers
What is the purpose of the condition if i % 2 == 0:
in the loop for i in range(5): if i % 2 == 0: if i != 0: print(f"{i} is even and not zero.") else: print(f"{i} is odd.")
?
What is the purpose of the condition if i % 2 == 0:
in the loop for i in range(5): if i % 2 == 0: if i != 0: print(f"{i} is even and not zero.") else: print(f"{i} is odd.")
?
Signup and view all the answers
What is the output of the code if data['info']['status'] == 'active' and data['info']['count'] > 30: result = 'Proceed' else: result = 'Hold'
?
What is the output of the code if data['info']['status'] == 'active' and data['info']['count'] > 30: result = 'Proceed' else: result = 'Hold'
?
Signup and view all the answers
What does the code if s[:5] == 'Hello': print('Greeting detected!') else: print('No greeting.') print?
What does the code if s[:5] == 'Hello': print('Greeting detected!') else: print('No greeting.') print?
Signup and view all the answers
What will be the output of the code snippet involving a loop and an if statement: numbers = [1, 2, 3, 4, 5]; sum = 0; for n in numbers: if n % 2 == 0: sum += n; print(sum)?
What will be the output of the code snippet involving a loop and an if statement: numbers = [1, 2, 3, 4, 5]; sum = 0; for n in numbers: if n % 2 == 0: sum += n; print(sum)?
Signup and view all the answers
What are the values of a and b after the swap in the code: a = 5; b = 10; if a < b: a, b = b, a?
What are the values of a and b after the swap in the code: a = 5; b = 10; if a < b: a, b = b, a?
Signup and view all the answers
What is the output of the code that includes an if-else structure within a loop: numbers = [5, 3, 10, 18, 6, 20]; for num in numbers: if num % 2 == 0: print('Even') else: print('Odd')?
What is the output of the code that includes an if-else structure within a loop: numbers = [5, 3, 10, 18, 6, 20]; for num in numbers: if num % 2 == 0: print('Even') else: print('Odd')?
Signup and view all the answers
What is the value of message in the code: x = 30; y = 40; if x > 10: if y < 50: message = 'Both conditions met.' else: message = 'Second condition failed.' else: message = 'First condition failed.'?
What is the value of message in the code: x = 30; y = 40; if x > 10: if y < 50: message = 'Both conditions met.' else: message = 'Second condition failed.' else: message = 'First condition failed.'?
Signup and view all the answers
What happens when the code a = 5; b = 10; if a < b: a, b = b, a is executed?
What happens when the code a = 5; b = 10; if a < b: a, b = b, a is executed?
Signup and view all the answers
What is the purpose of the if statement in the code: numbers = [1, 2, 3, 4, 5]; sum = 0; for n in numbers: if n % 2 == 0: sum += n?
What is the purpose of the if statement in the code: numbers = [1, 2, 3, 4, 5]; sum = 0; for n in numbers: if n % 2 == 0: sum += n?
Signup and view all the answers
What is the output of the code: s = 'Hello World'; if s[:5] == 'Hello': print('Greeting detected!') else: print('No greeting.')?
What is the output of the code: s = 'Hello World'; if s[:5] == 'Hello': print('Greeting detected!') else: print('No greeting.')?
Signup and view all the answers
What does the code numbers = [5, 3, 10, 18, 6, 20]; for num in numbers: if num % 2 == 0: print('Even') else: print('Odd') do?
What does the code numbers = [5, 3, 10, 18, 6, 20]; for num in numbers: if num % 2 == 0: print('Even') else: print('Odd') do?
Signup and view all the answers