Sofea is a TikTok user. Topics she likes include gym, cooking, travel, gardening and art. Imagine her TikTok feed is a 1D array that starts with 5 elements and can constantly be updated. Make a text-based user interface where a subject she likes will be displayed as a string (simulating a post) with equal chance of being about gym, cooking, travel, gardening or art, Provide functions that allow her to like, scroll past, or refresh when given a new post. Make sure user input is validated.
If she likes the post, append a new element to the 1D array with a 5% increased chance of it being that topic (e.g. if she likes ‘easy cake recipe’, the future post should have an increased chance of it being about cooking), make sure the new probability of that topic is stored. Then, clear the console (not the 1D array) and print the next post.
If she scrolls past the post, append a new element to the 1D array with a 5% decreased chance of being that topic, make sure the new probability of that topic is stored. Then, clear the console and print the next post.
If she refreshes at that post, clear the 1D array and append 5 new elements to it based on the stored probabilities, repeating the process.
(it’s ok if posts are repeated in the feed)
Starter code:
posts = [ [['gym etiquette'], ['shoulder workouts'], ['how to get a six pack fast'], ['stop doing this at the gym'], ['best leg day workouts']] , [['easy cake recipe'], ['essential ingredients for sushi'], ['my life as a 5* cook'], ['making subs in a subway'], ['top 5 chinese takeouts in London']] , [['how i got 9 for my IGCSE art'], ['tips for beginner artists'], ['draw spongebob, win $5'], ['the history of Banksy'], ['how to draw anime eyes']] , [['my trip to Ghana'], ['climbing 10 mountains in 100 days'], ['top 3 travel essentials'], ['how to pack efficiently'], ['top 5 places to visit in Mumbai']] , [['watching grass grow until 1M followers'], ['top 10 fruits to homegrow'], ['how to grow oranges'], ['this is the best fertiliser (not sponsored)'], ['why you should plant aloe vera at home']] ]
feed = []