3
\$\begingroup\$

I have written this code and I wonder if there is a better way to do absolutely any of it. Also, if there is any way to optimise it or if there is a problem please also tell me preferably with fixed code as I am still sort of a beginner. It is one of my first school projects and I would like to show my teacher that I really now Python. What it is supposed to do is take an input which is a YouTube and give a response based on the input. I've heard of dictionary lookups but I don't really understand what they are so if anyone thinks that they maybe relevant and could show me how to impliment it that would be great! I am also thinking of using a switch statement (which might be the same as a dictionary lookup) that I know from my experience with JavaScript. The code is below:

import random

def test():
    youtuber = input('Enter your favourite youtuber:  ')
    youtuber = youtuber.lower()
    favouriteYoutuber = ['Dr. Phil', 'Mr. Beast', 'T-Series', 'PewDiePie', '5 Minute Crafts', 'The Ellen Show']

    if youtuber == 'dr. phil':
        print('You are an awesome lad!')
    elif youtuber == 'james charles':
        print('Errmm. Ok...')
    elif youtuber == 'bloamz':
        print('Ok then.')
    elif youtuber == 'ali a':
        print('I mean. Thats old but ok...')
    elif youtuber == 'jacksepticeye':
        print('Thats kinda cool')
    elif youtuber == 'will smith':
        print('Thats different. I rate that')
    elif youtuber == 'jack black':
        print('you have good taste')
    elif youtuber == 'jack white':
        print('I like him as well')
    elif youtuber == 'dr. mike':
        print('so you like learning then')
    elif youtuber == 'morgz':
        print('I mean just leave now')
    else:
        print('I dont know that one. Ill check them out')

    print('my favourite youtuber is ' + random.choice(favouriteYoutuber))

def try_again():
    again = True
    while again:
        test()
        while True:
            try:
                print("")
                print("Would you like to try again?")
                maybe = input("Y/N ")
                maybe = maybe.lower()
            except ValueError:
                print("That is not a valid option")
                print("")
                continue
            if maybe in ('y','n'):
                if maybe == "n":
                    print("")
                    again = False
                elif maybe == "y":
                    print("")
                break

    else:
        print("Thank you for using this app!")
try_again()
\$\endgroup\$
0