+ 2
Help me
Tell me how can I improve it? https://sololearn.com/compiler-playground/cT02yMLDEsuf/?ref=app
1 Answer
+ 2
Hi HASAN IMTIAZ !
For improvements, I can suggest some. But first, that's a creative and well-thought code right there! Nice work!
Anyway, some minor suggestions: on the try-except block, the except block won't run as there will be no errors that will get caught (regardless of the input).
If I input "" or "2" it will just proceed to the method and check accordingly.
So you can just omit the try-except block since you have already handled the input validation inside the method anyway. đ
For code writing, if you want more readability and modularity, you can have separate methods for each truth and dare, and have the input validation outside the methods.
Or if you want a more concise and straightforward approach you can just have if-elif-else sequence and print the results right away:
if user_inp.lower() == "truth":
print("\nYou have chosen truth")
print(random.choice(truths))
...
But this is still according to your preference. Your current approach is still valid and well-structured! :)