Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def fibonacci_function():
- a, b = 0, 1
- while b < 35:
- a, b = b, a+b
- print(f"First: {a}, and then: {b}")
- print("Fibonacci")
- def counting_function():
- a, b = 0, 1
- while b < 35:
- a, b = a+1, b+1
- print(f"First: {a}, and then: {b}")
- print("Counting")
- #Only used once but just to show an implementation. "[input]" in invalid_message will be replaced with user_choice
- def get_input(valid_inputs, input_message = ": ", invalid_message = "Invalid input. Try again."):
- user_choice = input(input_message)
- while user_choice not in valid_inputs:
- #Allow for showing user input in error message
- parsed_invalid_message = invalid_message.replace("[input]", user_choice)
- print(parsed_invalid_message)
- user_choice = input(input_message)
- return user_choice
- user_choice = get_input(["Fibonacci", "Spiral", "Counting", "Count"],
- "What do you want me to do? ",
- "[input] is not valid.")
- #Array to determine whether or not the user has chosen fibonacci
- fibonacci_choices = ["Fibonacci", "Spiral"]
- if user_choice in fibonacci_choices:
- fibonacci_function()
- else:
- counting_function()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement