Day1: Learning to Use the input() Function in Python to Collect User Input
How to use Python’s input() function to collect data from a user and integrate it into my code. It’s a super useful function when you need interactive programs!
?? PAUSE 1: Using input() to Collect User Input and Add an Exclamation Mark
We can use the input() function to ask the user for their name, then combine it with other strings using string concatenation to form a complete sentence.
Here’s how you can do it:
# Collecting user input
name = input("What is your name? ")
# Concatenating the input with other strings and adding an exclamation mark
greeting = "Hello " + name + "!"
# Printing the result
print(greeting)
?? Explanation:
???? Example Output:
If the user enters "Hanzalah", the output will be:
What is your name? Hanzalah
Hello Hanzalah!
This is a simple but powerful way to personalize your program's output based on user input. It’s also a great stepping stone for more complex programs that require user interaction!
Stay tuned as I continue my Python journey and explore more coding skills during my #100DaysOfCode! ??