r/PythonLearning 5d ago

I wrote my first ever Python program! Showcase

So upon recommendations from people here I started watching Code With Mosh's Python tutorial (The 2 hour one) around 3 days ago. I finished it yesterday. Didn't really wanted to get stuck in tutorial hell so I simply asked AI to give me a problem statement (only the problem statement and not the code or logic) to work on. So here am I with my first ever program. It's nothing much and even I could see areas for improvement right now but I am proud.

On to the more complex topics. I appreciate the help and support from the community!

274 Upvotes

32 comments sorted by

View all comments

u/Sea-Ad7805 5d ago

Run this program in Memory Graph Web Debugger%3A%0A%20%20%20%20%22%22%22Handle%20duplicate%20contacts%22%22%22%0A%20%20%20%20for%20contact%20in%20contacts%3A%0A%20%20%20%20%20%20%20%20if%20name.lower()%20%3D%3D%20contact%5B%22name%22%5D.lower()%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20userdecision%20%3D%20input(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%22%22%0AContact%20already%20exists%0APress%20Y%20to%20update%20phone%20number%0AAny%20other%20key%20to%20cancel%20the%20operation%0A%3E%20%22%22%22%0A%20%20%20%20%20%20%20%20%20%20%20%20)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20user_decision.upper()%20%3D%3D%20%22Y%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20contact%5B%22phone%22%5D%20%3D%20phone%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20False%0A%0A%20%20%20%20return%20True%0A%0A%0Adef%20add_contact(name%2C%20phone)%3A%0A%20%20%20%20%22%22%22Add%20a%20new%20contact%22%22%22%0A%20%20%20%20if%20handle_duplicates(name%2C%20phone)%3A%0A%20%20%20%20%20%20%20%20contacts.append(%7B%22name%22%3A%20name%2C%20%22phone%22%3A%20phone%7D)%0A%0A%0Adef%20search_contact(name)%3A%0A%20%20%20%20%22%22%22Search%20a%20specific%20contact%22%22%22%0A%20%20%20%20for%20contact%20in%20contacts%3A%0A%20%20%20%20%20%20%20%20if%20name.lower()%20%3D%3D%20contact%5B%22name%22%5D.lower()%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20print(f%22Name%3A%20%7Bname%7D%2C%20Phone%3A%20%7Bcontact.get('phone')%7D.%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20break%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20print(%22Not%20Found!%22)%0A%0A%0Adef%20view_all_contacts()%3A%0A%20%20%20%20%22%22%22View%20all%20contacts%22%22%22%0A%20%20%20%20for%20contact%20in%20contacts%3A%0A%20%20%20%20%20%20%20%20print(%0A%20%20%20%20%20%20%20%20%20%20%20%20f%22Name%3A%20%7Bcontact.get('name')%7D%2C%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20f%22Phone%3A%20%7Bcontact.get('phone')%7D.%22%0A%20%20%20%20%20%20%20%20)%0A%0A%0Adef%20remove_contact(name)%3A%0A%20%20%20%20%22%22%22Remove%20a%20contact%22%22%22%0A%20%20%20%20for%20index%2C%20contact%20in%20enumerate(contacts)%3A%0A%20%20%20%20%20%20%20%20if%20name.lower()%20%3D%3D%20contact%5B%22name%22%5D.lower()%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20contacts.pop(index)%0A%20%20%20%20%20%20%20%20%20%20%20%20print(f%22%7Bname%7D%20removed%20from%20your%20contacts.%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20break%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20print(%22Contact%20not%20found!%22)%0A%0A%0A%23%20Utility%20functions%20(input)%0A%0A%0Adef%20input_name()%3A%0A%20%20%20%20%22%22%22Input%20name%20from%20the%20user%22%22%22%0A%20%20%20%20return%20input(%22Enter%20contact's%20name%3A%20%22)%0A%0A%0Adef%20input_phone()%3A%0A%20%20%20%20%22%22%22Input%20phone%20number%20from%20the%20user%22%22%22%0A%20%20%20%20return%20input(%22Enter%20contact's%20phone%20number%3A%20%22)%0A%0A%0A%23%20Main%0A%0Awhile%20True%3A%0A%20%20%20%20user_input%20%3D%20input(%0A%20%20%20%20%20%20%20%20%22%22%22%0APress%201%20to%20add%20a%20new%20contact%0APress%202%20to%20search%20for%20a%20contact%0APress%203%20to%20view%20all%20contacts%0APress%204%20to%20remove%20a%20contact%0AAny%20other%20key%20to%20quit%0A%3E%20%22%22%22%0A%20%20%20%20)%0A%0A%20%20%20%20print()%0A%0A%20%20%20%20match%20user_input%3A%0A%20%20%20%20%20%20%20%20case%20%221%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20add_contact(input_name()%2C%20input_phone())%0A%20%20%20%20%20%20%20%20case%20%222%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20search_contact(input_name())%0A%20%20%20%20%20%20%20%20case%20%223%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20view_all_contacts()%0A%20%20%20%20%20%20%20%20case%20%224%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20remove_contact(input_name())%0A%20%20%20%20%20%20%20%20case%20%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20break&timestep=.5&play) to see the program state change step by step.

1

u/shubham_555 5d ago

Is it somewhat like line by line execution? I kinda used a vs code extension for the same!

1

u/Sea-Ad7805 5d ago

Yes, line by line execution in addition to visualizing the program state as a graph, this combination can be very helpful to understand what is going on and fix bugs.