SimeonTs

SUPyF2 Basic Exercise More - 03. Wolf In Sheep's Clothing

Sep 24th, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.64 KB | None | 0 0
  1. """
  2. Basic Syntax, Conditional Statements and Loops - Exercise
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1720#2
  4. Video: https://www.youtube.com/watch?time_continue=4&v=7sHE4HEUqi8
  5.  
  6. SUPyF2 Basic Exercise More - 03. Wolf In Sheep's Clothing
  7.  
  8. Problem:
  9. Wolves have been reintroduced to Great Britain. You are a sheep farmer,
  10. and are now plagued by wolves which pretend to be sheep. Fortunately, you are good at spotting them.
  11. Warn the sheep in front of the wolf that it is about to be eaten.
  12. Remember that you are standing at the front of the queue which is at the end of the array:
  13. [sheep, sheep, wolf, sheep, sheep] (YOU ARE HERE AT THE FRONT OF THE QUEUE)
  14.   4      3            2      1
  15. If the wolf is the closest animal to you, print "Please go away and stop eating my sheep".
  16. Otherwise, return "Oi! Sheep number N! You are about to be eaten by a wolf!"
  17. where N is the sheep's position in the queue.
  18. Note: there will always be exactly one wolf in the array.
  19.  
  20. Input:
  21. The input will be a single string containing the animals separated by comma and a single space ", "
  22.  
  23. Examples:
  24. Input:                                          Output:
  25. sheep, sheep, wolf                              Please go away and stop eating my sheep
  26. wolf, sheep, sheep, sheep, sheep, sheep         Oi! Sheep number 5! You are about to be eaten by a wolf!
  27. """
  28.  
  29. text = [animal for animal in input().split(", ")]
  30. if text[len(text) - 1] == "wolf":
  31.     print("Please go away and stop eating my sheep")
  32. else:
  33.     text.reverse()
  34.     sheep_to_be_eaten = text.index("wolf")
  35.     print(f"Oi! Sheep number {sheep_to_be_eaten}! You are about to be eaten by a wolf!")
Add Comment
Please, Sign In to add comment