Challenge - 5 Problems
Input Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this code when input is '5'?
Consider the following Python code that takes input and processes it:
Python
num = input("Enter a number: ") result = int(num) * 2 print(result)
Attempts:
2 left
💡 Hint
Remember that input() returns a string and you need to convert it to an integer before multiplying.
✗ Incorrect
The input '5' is read as a string. Using int() converts it to the number 5. Multiplying by 2 gives 10, which is printed.
❓ Predict Output
intermediate2:00remaining
What will be printed if the input is 'hello'?
Look at this code snippet:
Python
user_input = input("Say something: ") print(user_input * 3)
Attempts:
2 left
💡 Hint
Multiplying a string by a number repeats the string that many times.
✗ Incorrect
The input 'hello' is a string. Multiplying it by 3 repeats it three times without spaces.
❓ Predict Output
advanced2:00remaining
What error does this code raise if input is 'abc'?
Analyze this code:
Python
value = int(input("Enter a number: ")) print(value + 10)
Attempts:
2 left
💡 Hint
int() cannot convert non-numeric strings to integers.
✗ Incorrect
Trying to convert 'abc' to int causes a ValueError because 'abc' is not a valid number.
❓ Predict Output
advanced2:00remaining
What is the output if the input is '3 4'?
Consider this code:
Python
a, b = input("Enter two numbers separated by space: ").split() print(int(a) + int(b))
Attempts:
2 left
💡 Hint
split() divides the input string into parts separated by spaces.
✗ Incorrect
Input '3 4' splits into '3' and '4'. Converting both to int and adding gives 7.
❓ Predict Output
expert2:00remaining
What is the output of this code if input is '10'?
Examine this code carefully:
Python
num = input("Enter a number: ") match num: case '10': print("Ten") case _: print("Not Ten")
Attempts:
2 left
💡 Hint
match-case compares the input string exactly to the case values.
✗ Incorrect
Input '10' matches the case '10', so it prints 'Ten'.