Question: I am trying to select a random word from a txt file. The context of the file has been provided. I would like the word to be random every time the code is ran. I also only need the words before the comma

```
import random 
print("Please enter mywords file to start game")

user_input=input('Enter file name')
filename = open(user_input)
info=filename.readlines()
filename.close()

words=info[0-3]
objects=words.split(',')
userword=random.choice(objects)
print(userword)

```

```none
opulence,great wealth
penury,extremely poor
gregarious,fond of company; sociable
entomology,study of insects

```

So far I able to pull from the second line in the file 
"penury,extremely poor"

Answer: 
You can further simplify the code you're using.

```
public function index(Request $request)
{
    $page = $request->page;
    return response([
        'posts' => $page === 'all' ? Post::all() :  Post::paginate($page)
    ], Response::HTTP_OK);
}

```
Avoid load several time of model instance. 

```
public function index(Request $request)
{
  $post = Post::query();
  $data = ($request->page === 'all') ? $post : $post->paginate(10);
  return response()->json(['posts' => $data], 200);
}

```