Answer to Question #100515 in Python for Tirthajoti sinha

Question #100515
Develop a Python script to have a list of tourist destinations given as input each of which is worthy for a visit. We would like to select one or more randomly from the list. If the chosen one is not liked by the user, it can be rejected to select another set randomly. This will be continued until the user responds with ‘y’. Each time before the random selection, the list should be shown with rearranged values to rule out any biasness. The selection can be done repeatedly until the user signals ‘no more selection required’.
1
Expert's answer
2019-12-16T14:50:43-0500
import random


tourist_destinations = ['Prague Castle', 'Charles Bridge', 'Wenceslas Square',
'The National Museum', 'The Clementinum and the National Library', 
'The Old Town Square and the Astronomical Clock', 'St. Vitus Cathedral',
'The Church of Our Lady before Týn', 'The National Gallery in Prague',
'The Municipal House', 'Prague Zoo', 'Josefov: The Jewish Quarter',
'The Strahov Monastery and Library', 'The Petrín Lookout Tower', 'The Lennon Wall']


def destinations(arr):
    print('We will provide you with tourist destinations. You can choose your favorite.')
    print('Press "y" to choose, press "n" to reject')
    try:
        choice = random.choice(arr)
        print(choice)
        answer = input('Does it suit you? ')
        while (answer != 'y') and (answer != 'n'):
            print('Please answer "y" or "n"')
            answer = input('Does it suit you? ')
        if answer == 'y':
            print('Thank you for using our service.')
        elif answer == 'n':
            arr.remove(choice) 
            destinations(arr)
        else:
            print('Unknown error. Sorry. Will be fixed')
    except IndexError:
        print('no more selection required')
    
if __name__ == '__main__':
    destinations(tourist_destinations)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS