Challenge - 5 Problems
String Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediateOutput of string length and membership test
What is the output of this Python code?
Python
s = "hello world" result = len(s) > 5 and 'w' in s print(result)
Attempts:
2 left
๐ก Hint
Check if the string length is greater than 5 and if the character 'w' is inside the string.
โ Incorrect
The string 'hello world' has length 11, which is greater than 5, and it contains the character 'w'. So both conditions are True, making the result True.
โ Predict Output
intermediateCheck membership and length in a string
What will be printed by this code?
Python
text = "Python3.12" output = ('3' in text) and (len(text) == 9) print(output)
Attempts:
2 left
๐ก Hint
Check if '3' is in the string and if the length equals 9.
โ Incorrect
The string 'Python3.12' contains '3' but its length is 10, not 9, so the expression evaluates to False.
โ Predict Output
advancedResult of combined string length and membership test
What is the output of this code snippet?
Python
s = "DataScience" result = (len(s) < 10) or ('a' not in s) print(result)
Attempts:
2 left
๐ก Hint
Evaluate both conditions and then the or operation.
โ Incorrect
The length of 'DataScience' is 11, so len(s) < 10 is False. The character 'a' is in the string, so 'a' not in s is False. False or False is False.
โ Predict Output
advancedOutput of membership test with string length check
What does this code print?
Python
word = "challenge" print(len(word) == 9 and 'z' in word)
Attempts:
2 left
๐ก Hint
Check the length and if 'z' is in the string.
โ Incorrect
The length of 'challenge' is 9, so len(word) == 9 is True. But 'z' is not in the string, so 'z' in word is False. True and False is False.
๐ง Conceptual
expertUnderstanding string membership and length logic
Given the code below, what is the value of variable result after execution?
Python
text = "OpenAI GPT" result = (len(text) != 10) and (' ' in text) and ('A' in text)
Attempts:
2 left
๐ก Hint
Check each condition carefully and combine with 'and'.
โ Incorrect
The string 'OpenAI GPT' has length 10, so len(text) != 10 is False. Since the first condition is False, the whole 'and' expression is False regardless of the others.
