🎩 Master Quiz: Input Handling
20 Questions. Capturing data, Security Gates, and Avoiding the Type Trap.
Green = Correct, Red = Incorrect.
In the “Security Gate” analogy, what represents the input() function?
💡 Explanation
The Guard.
input() is the entity that pauses the flow and asks the visitor (user) for information.
What data type does input() ALWAYS return by default?
💡 Explanation
String (str).
Even if the user types a number like 100, Python treats it as text "100" unless you cast it.
Which syntax correctly prompts the user for a name?
💡 Explanation
input("Message")
You pass the prompt string directly inside the input() function parentheses.
What happens if you run age = input("Age: ") and type 20, then age + 1?
💡 Explanation
TypeError.
You cannot add an Integer (1) to a String (“20”). You must convert age to an int first.
How do you correctly capture an Integer from the user?
💡 Explanation
Wrap input() in int().
This explicitly converts the string returned by input into an integer immediately.
Why is accepting raw input dangerous for Admin scripts?
💡 Explanation
Security risks.
Architects must implement Input Validation. Raw input can crash a server or lead to security vulnerabilities if not sanitized.
Why is input() NOT suitable for CI/CD pipelines (like Jenkins)?
💡 Explanation
It blocks execution.
Since pipelines are automated, there is no human to type the answer. The job will hang indefinitely and fail.
What is the industry-standard tool for creating CLI tools (Automation)?
💡 Explanation
argparse.
For automated DevSecOps tools, we use Command Line Arguments via argparse so scripts run without human intervention.
Which module allows basic command-line input via sys.argv?
💡 Explanation
sys.
sys.argv provides a simple list of arguments passed to the script at runtime.
What does “Blocking” mean in the context of input()?
💡 Explanation
Program pauses.
Code execution stops at the input() line and waits for the user to provide data and hit Enter.
How do you capture a decimal price from the user?
💡 Explanation
float(input(...)).
Just like int(), you wrap the input function with float() to handle decimal numbers.
How can you capture two values (e.g., “10 20”) in one line?
💡 Explanation
.split().
split() breaks the string by spaces, allowing you to unpack multiple values into variables instantly.
In the “Security Gate” analogy, what corresponds to the “Visitor”?
💡 Explanation
The Keyboard.
The Visitor provides the data, just as you provide data via the keyboard.
In the “Security Gate” analogy, what is the “Register”?
💡 Explanation
The Variable.
The guard writes the information down in a register (Variable) so it can be used later.
What is the result of x = input() (user types 10) + "10"?
💡 Explanation
“1010”.
Since input returns a string “10”, adding another string “10” performs concatenation, not math.
What is “Type Sanitization”?
💡 Explanation
Convert to expected type immediately.
Architects ensure data integrity by validating and converting raw input into its proper type (int, float) before using it.
What is a good use case for input()?
💡 Explanation
Interactive Provisioning.
Scripts that require human decisions (e.g., “Which AWS Region?”) are perfect for input().
When is input() crucial for safety?
💡 Explanation
Confirmation steps.
Pausing to ask “Are you sure you want to delete this production bucket?” prevents catastrophic accidents.
What is the benefit of adding a message inside input("...")?
💡 Explanation
It guides the user.
Without a prompt, the user sees a blinking cursor and doesn’t know what data is expected.
How does Input Handling improve a script?
💡 Explanation
Makes it dynamic.
Instead of hard-coding values like region="us-east-1", input allows one script to work for any region based on user choice.