Python Input Quiz
Progress
Score: 0/20
๐ฉ Master Quiz: Input Handling
20 Questions. Capturing data, Security Gates, and Avoiding the Type Trap. Green = Correct, Red = Incorrect.
BeginnerAnalogy
In the "Security Gate" analogy, what represents the input() function?โ
- **A) The Visitor
** - **B) The Guard (asking questions)
** - **C) The Register (Variable)
** - **D) The Apartment
**
๐ก Explanationโ
The Guard.
input() is the entity that pauses the flow and asks the visitor (user) for information.
BeginnerReturn Type
What data type does input() ALWAYS return by default?โ
- **A) Integer (int)
** - **B) Whatever the user types
** - **C) String (str)
** - **D) Boolean
**
๐ก Explanationโ
String (str).
Even if the user types a number like 100, Python treats it as text "100" unless you cast it.
BeginnerSyntax
Which syntax correctly prompts the user for a name?โ
- **A)
name = input("Enter Name: ")``** - **B)
input(name, "Enter Name: ")``** - **C)
print("Enter Name: ")``** - **D)
get_input("Name")``**
๐ก Explanationโ
input("Message")
You pass the prompt string directly inside the input() function parentheses.
TrapType Trap
What happens if you run age = input("Age: ") and type 20, then age + 1?โ
- **A) 21
** - **B) TypeError (Crash)
** - **C) "201"
** - **D) 20
**
๐ก Explanationโ
TypeError.
You cannot add an Integer (1) to a String ("20"). You must convert age to an int first.
SolutionCasting
How do you correctly capture an Integer from the user?โ
- **A)
input(int("Age: "))``** - **B)
input("Age: ").to_int()``** - **C)
int(input("Age: "))``** - **D)
input("Age: ", type=int)``**
๐ก Explanationโ
Wrap input() in int().
This explicitly converts the string returned by input into an integer immediately.
ArchitectInput Validation
Why is accepting raw input dangerous for Admin scripts?โ
- **A) Security risks (Injection/Crashes)
** - **B) It uses too much memory
** - **C) It makes the code ugly
** - **D) It is deprecated
**
๐ก Explanationโ
Security risks.
Architects must implement Input Validation. Raw input can crash a server or lead to security vulnerabilities if not sanitized.
ArchitectCI/CD
Why is input() NOT suitable for CI/CD pipelines (like Jenkins)?โ
- **A) It is too fast
** - **B) It blocks execution (Timeout/Hang)
** - **C) Jenkins doesn't support Python
** - **D) It prints too many logs
**
๐ก Explanationโ
It blocks execution.
Since pipelines are automated, there is no human to type the answer. The job will hang indefinitely and fail.
ArchitectAutomation Tool
What is the industry-standard tool for creating CLI tools (Automation)?โ
- **A)
input()``** - **B)
text_prompt``** - **C)
argparse``** - **D)
sys.input``**
๐ก Explanationโ
argparse.
For automated DevSecOps tools, we use Command Line Arguments via argparse so scripts run without human intervention.
AdvancedCLI Basics
Which module allows basic command-line input via sys.argv?โ
- **A)
sys``** - **B)
os``** - **C)
cli``** - **D)
cmd``**
๐ก Explanationโ
sys.
sys.argv provides a simple list of arguments passed to the script at runtime.
CoreBehavior
What does "Blocking" mean in the context of input()?โ
- **A) It stops hackers
** - **B) The program pauses until "Enter" is pressed
** - **C) It runs in the background
** - **D) It deletes previous data
**
๐ก Explanationโ
Program pauses.
Code execution stops at the input() line and waits for the user to provide data and hit Enter.
SyntaxFloat Input
How do you capture a decimal price from the user?โ
- **A)
input("Price: ", float)``** - **B)
decimal(input("Price: "))``** - **C)
float(input("Price: "))``** - **D)
input_float("Price: ")``**
๐ก Explanationโ
float(input(...)).
Just like int(), you wrap the input function with float() to handle decimal numbers.
AdvancedMultiple Inputs
How can you capture two values (e.g., "10 20") in one line?โ
- **A)
x, y = input().split()``** - **B)
x, y = input()``** - **C)
input().two_values()``** - **D)
x = input(); y = input()``**
๐ก Explanationโ
.split().
split() breaks the string by spaces, allowing you to unpack multiple values into variables instantly.
AnalogyVisitor
In the "Security Gate" analogy, what corresponds to the "Visitor"?โ
- **A) The Variable
** - **B) The Screen
** - **C) The Keyboard (Providing Data)
** - **D) The Guard
**
๐ก Explanationโ
The Keyboard.
The Visitor provides the data, just as you provide data via the keyboard.
AnalogyVariable
In the "Security Gate" analogy, what is the "Register"?โ
- **A) The input function
** - **B) The Variable (where data is stored)
** - **C) The Prompt Message
** - **D) The Enter Key
**
๐ก Explanationโ
The Variable.
The guard writes the information down in a register (Variable) so it can be used later.
IntermediateConcatenation
What is the result of x = input() (user types 10) + "10"?โ
- **A) "1010" (String)
** - **B) 20 (Int)
** - **C) TypeError
** - **D) 10
**
๐ก Explanationโ
"1010".
Since input returns a string "10", adding another string "10" performs concatenation, not math.
ArchitectSanitization
What is "Type Sanitization"?โ
- **A) Cleaning your keyboard
** - **B) Converting input to the expected type immediately
** - **C) Removing spaces
** - **D) Encrypting the input
**
๐ก 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.
Use CaseInteractive
What is a good use case for input()?โ
- **A) A nightly backup script
** - **B) A Kubernetes Autoscaler
** - **C) An interactive Cloud Provisioning script
** - **D) A web server
**
๐ก Explanationโ
Interactive Provisioning.
Scripts that require human decisions (e.g., "Which AWS Region?") are perfect for input().
Use CaseSafety
When is input() crucial for safety?โ
- **A) Confirmation steps (Yes/No) before deletion
** - **B) Logging errors
** - **C) Calculating CPU usage
** - **D) Reading files
**
๐ก Explanationโ
Confirmation steps.
Pausing to ask "Are you sure you want to delete this production bucket?" prevents catastrophic accidents.
AdvancedPrompt Message
What is the benefit of adding a message inside input("...")?โ
- **A) It makes the script run faster
** - **B) It guides the user on what to type
** - **C) It converts the type automatically
** - **D) It encrypts the prompt
**
๐ก Explanationโ
It guides the user.
Without a prompt, the user sees a blinking cursor and doesn't know what data is expected.
ArchitectFlexibility
How does Input Handling improve a script?โ
- **A) It makes it dynamic instead of hard-coded
** - **B) It reduces file size
** - **C) It prevents all errors
** - **D) It automatically updates Python
**
๐ก 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.
๐ Quiz Complete!โ
Your Final Score:
0/20 Novice
Keep practicing to reach Architect level!
- **โบ Retake Quiz
**