π 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ΒΆ
-
A string of fruit emojis is stored in
fruit_line
. - The user is asked to input two numbers: a start index and an end index.
- If the start index is greater than the end index, the program swaps them automatically.
- A slice of the fruit string is taken between the two indices.
- 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Β [Β ]: