πŸ“ Fruit Picker GameΒΆ

This is a fun little Python project that lets users select a range of fruits from a string of fruit emojis based on index positions. It's a great way to practice:

  • User input
  • String slicing
  • Index validation
  • Conditional logic

🧠 How It Works¢

  1. A string of fruit emojis is stored in fruit_line.
  2. The user is asked to input two numbers: a start index and an end index.
  3. If the start index is greater than the end index, the program swaps them automatically.
  4. A slice of the fruit string is taken between the two indices.
  5. The selected fruits are displayed!
InΒ [Β ]:
fruit_line = 'πŸŽπŸπŸπŸŠπŸ‹πŸŒπŸ‰πŸ‡πŸ“πŸ«πŸˆπŸ’πŸ‘πŸ₯­πŸπŸ₯₯πŸ₯πŸ…πŸ«’'
max_index = len(fruit_line) - 1

start_index = int(input(f'Pick a starting index between 0 and {max_index}:'))
end_index = int(input(f'Pick an ending index between 0 and {max_index}, different from {start_index}:'))

# Ensure the start index is less than the end index
if start_index > end_index:
    start_index, end_index = end_index, start_index

selected_fruits = fruit_line[start_index:end_index]
print(f'\nYour selected fruits: {selected_fruits}')
InΒ [Β ]:
 

<< Back

Davina's Jupyter Notebooks © Davina Leong, 2025