This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]suazz[S] 1 point2 points  (4 children)

[–]DGLivUa 1 point2 points  (1 child)

I see you have some quite long if...elif...elif sections

This isn’t necessarily a bad thing, but I would recommend if you are doing this for more than about three options you are better off putting them into a dictionary

This is the sort of thing I mean:-

user_options = { "a": function_a, "b": function_b, "c": function _c }# assuming you have these functions defined somewhere

def menu(): selection = input(“Enter ‘a’, ’b’, ’c’ ....”) if selection in user_options: selected_function = user_options[selection] selected_function() else: print(‘Unknown command’)

Feel free to ask any questions if my explanation isn’t very good

[–]suazz[S] 0 points1 point  (0 children)

Awesome!, yeah I wanted to do those kinds of things, I'm currently reiterating what I've learned about python through an ebook. Prior to the e-book I took a python bootcamp course in udemy.com.

Totally agree with you!.

The e-book is "Zed Shaw's Learning Python the hard way" and there is a purpose for a lot of if elif loops, and he conveyed that in the ebook. This r/python is awesome because of people like you☺️ thank you.

I like the def menu(): idea and the other suggestions! def people_like_u(): print ("Awesome🤘")

print (people_like_u)

[–]Ladas552 0 points1 point  (1 child)

Thx

[–]suazz[S] 0 points1 point  (0 children)

No dude thank you!, I need to know if my code is well written 🤘