dimanche 29 avril 2018

Python Select random film from json by film type

import random
import json

# user_input = input('')

with open('robot.json') as f:
    data = json.load(f)

for film in data['films']:
    print(film["title"], film["category"])

In the code above, I want to add a user input that allows a user to specify the genre of film and using that response, retrieve a random selection from its respective category that is contained within the 'robot.json' file.

I can't seem to get random.choice to work, but that program will print all the entries in the json.

I am new to this, so I keep getting stuck in the weeds. Any help would be great.




Aucun commentaire:

Enregistrer un commentaire