Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. def fibonacci_function():
  2. a, b = 0, 1
  3. while b < 35:
  4. a, b = b, a+b
  5. print(f"First: {a}, and then: {b}")
  6. print("Fibonacci")
  7.  
  8. def counting_function():
  9. a, b = 0, 1
  10. while b < 35:
  11. a, b = a+1, b+1
  12. print(f"First: {a}, and then: {b}")
  13. print("Counting")
  14.  
  15. #Only used once but just to show an implementation. "[input]" in invalid_message will be replaced with user_choice
  16. def get_input(valid_inputs, input_message = ": ", invalid_message = "Invalid input. Try again."):
  17. user_choice = input(input_message)
  18.  
  19. while user_choice not in valid_inputs:
  20. #Allow for showing user input in error message
  21. parsed_invalid_message = invalid_message.replace("[input]", user_choice)
  22. print(parsed_invalid_message)
  23. user_choice = input(input_message)
  24.  
  25. return user_choice
  26.  
  27. user_choice = get_input(["Fibonacci", "Spiral", "Counting", "Count"],
  28. "What do you want me to do? ",
  29. "[input] is not valid.")
  30.  
  31. #Array to determine whether or not the user has chosen fibonacci
  32. fibonacci_choices = ["Fibonacci", "Spiral"]
  33.  
  34. if user_choice in fibonacci_choices:
  35. fibonacci_function()
  36.  
  37. else:
  38. counting_function()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement