I have written this code which provides advice based on user's favourite YouTuber. 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. The code is below: ```Python 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()
Thanks for everyone's advice. I have no re-done my program and it would be great if you could spot anything that I could further improve I have written this code which provides advice based on user's favourite YouTuber. 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. The code is below:
import random
def favorite_youtuber():
print("")
youtube_response = {
'dr. phil': ['You are an awesome lad!',9],
'james charles': ['Errmm. Ok...', 2],
'bloamz': ['Ok then.',6],
'ali a': ['I mean. Thats old but ok...',3.5],
'jacksepticeye': ['He is kinda cool',8],
'will smith': ['Thats diferent. I rate that.',8],
'jack black': ['I like him as well',7.5],
'jack white': ['Oh yeah.. I like that',8],
'dr. mike': ['So you like learning then!',8.5],
'morgz': ['I mean just leave now.','... NO JUST NO!!!']
}
my_favorite_youtubers = ['Dr. Phil', 'Mr. Beast', 'T-Series', 'PewDiePie', '5 Minute Crafts', 'The Ellen Show']
youtuber = input('Enter your favourite youtuber: ').lower()
if youtuber in youtube_response:
print(youtube_response[youtuber][0])
print(f"I would give them a rating of {youtube_response[youtuber][1]}/10")
else:
print('I dont know that one. Ill check them out.')
print(f'My favourite youtuber is {random.choice(my_favorite_youtubers)}!')
print("")
def run_app():
while True:
favorite_youtuber()
again = input("Play again? (Y/N)").lower()
while again not in "yn":
print("That is not a valid option!")
again = input("Play again? (Y/N) ").lower()
print("")
if again == "n":
break
print("Thank you for using this app!")
if __name__ == "__main__":
run_app()
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()