Created
January 19, 2025 09:48
-
-
Save jmcph4/944c07660c1709dd9b42c7f0a489290b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def ask_question(question, choices=None): | |
print(question) | |
if choices: | |
for i, choice in enumerate(choices, 1): | |
print(f"{i}. {choice}") | |
answer = input("Choose a number: ") | |
return choices[int(answer) - 1] if answer.isdigit() and 1 <= int(answer) <= len(choices) else None | |
else: | |
return input("Your answer: ") | |
def main(): | |
print("Welcome to the Basic Questionnaire!\n") | |
name = ask_question("What is your name?") | |
print(f"Hello, {name}!\n") | |
age = ask_question("How old are you?") | |
print(f"You are {age} years old!\n") | |
likes_python = ask_question("Do you like programming in Python?", ["Yes", "No"]) | |
print(f"You answered: {likes_python}\n") | |
favorite_language = ask_question("What is your favorite programming language?", ["Python", "Java", "C++", "JavaScript"]) | |
print(f"Your favorite programming language is {favorite_language}.\n") | |
print("Thank you for answering the questions!") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment