Skip to main content

# Implementing Basic Prompt Logic

To implement basic prompt logic in your code, you can use a combination of input functions and conditional statements. Here’s a simple example in Python:

“`python
# Function to display a prompt and get user input
def get_user_input(prompt):
user_input = input(prompt)
return user_input

# Main program
if __name__ == “__main__”:
# Display a prompt and get user input
user_name = get_user_input(“Enter your name: “)

# Display a greeting based on user input
if user_name:
print(f”Hello, {user_name}! Welcome.”)
else:
print(“Hello, stranger! Welcome.”)
“`

In this code snippet:
1. We define a function `get_user_input(prompt)` that takes a prompt as an argument, displays it to the user, and returns the user’s input.
2. In the main program, we call `get_user_input` with the prompt “Enter your name:” to get the user’s name.
3. Based on the user input, we display a greeting message.

You can customize this logic further based on your specific requirements. Feel free to adapt the code to fit the language or platform you are working with.