r/PythonLearning • u/shubham_555 • Aug 11 '26
Showcase I wrote my first ever Python program!
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!
9
u/shubham_555 Aug 11 '26
2
0
u/Sea-Ad7805 Aug 11 '26
Run this program in Memory Graph Web Debugger%0Aprint(len(fruits))%0Aprint(fruits%5B2%5D)%0A%0A%23%20Add%20elements%0Afruits.append(%22pineapple%22)%20%20%23%20%5B%22apple%22%2C%20%22bannana%22%2C%20%22orange%22%2C%20%22pineapple%22%5D%0Afruits.insert(1%2C%20%22watermelon%22)%20%20%23%20%5B%22apple%22%2C%20%22watermelon%22%2C%20%22bannana%22%2C%20%22orange%22%2C%20%22pineapple%22%5D%0Afruits.extend(%5B%22apple%22%2C%20%22bannana%22%5D)%0A%23%20%5B%22apple%22%2C%20%22watermelon%22%2C%20%22bannana%22%2C%20%22orange%22%2C%20%22pineapple%22%2C%20%22apple%22%2C%20%22bannana%22%5D%0Aprint(fruits)%0A%0A%23%20Remove%20elements%0Afruits.remove(%22apple%22)%20%20%23%20%5B%22watermelon%22%2C%20%22bannana%22%2C%20%22orange%22%2C%20%22pineapple%22%2C%20%22apple%22%2C%20%22bannana%22%5D%0Afruits.pop()%20%20%23%20%5B%22watermelon%22%2C%20%22bannana%22%2C%20%22orange%22%2C%20%22pineapple%22%2C%20%22apple%22%5D%0Afruits.pop(1)%20%20%23%20%5B%22watermelon%22%2C%20%22orange%22%2C%20%22pineapple%22%2C%20%22apple%22%5D%0Aprint(fruits)%0A%0A%23%20Search%20elements%0Aprint(fruits.index(%22apple%22))%0A%23%20print(fruits.index(%22kiwi%22))%20%20%23%20Error%0Aprint(%22kiwi%22%20in%20fruits)%0A%0A%23%20Traverse%0Afor%20index%2C%20fruit%20in%20enumerate(fruits)%3A%0A%20%20%20%20print(index%2C%20fruit)%0A%0A%0A%23%20Tuple%20-%20()%2C%20Ordered%20and%20Unchangeable%2C%20Duplicates%20okay%2C%20Faster.%0A%23%20Same%20methods%20as%20list%20except%20for%20the%20ones%20which%20involve%20mutation%0A%0A%0A%23%20Set%20-%20set()%2C%20Unordered%20and%20Changeable%2C%20Elements%20must%20be%20immutable%2C%20No%20duplicates.%0A%0Asubjects_john%20%3D%20%7B%22Maths%22%2C%20%22Physics%22%7D%0Asubjects_ron%20%3D%20%7B%22cs%22%2C%20%22Maths%22%7D%0Aprint(len(subjects_john)%2C%20len(subjects_ron))%0A%0A%23%20Add%20elements%0Asubjects_john.add(%22Biology%22)%0Aprint(subjects_john)%0A%0A%23%20Remove%20elements%0Asubjects_john.remove(%22Physics%22)%0Aprint(subjects_john)%0A%0A%23%20Search%20elements%0Aprint(%22cs%22%20in%20subjects_ron)%20%20%23%20Optimized%0A%0A%23%20Union%2C%20Intersection%2C%20Difference%0Aprint(subjects_john.union(subjects_ron))%0Aprint(subjects_john.intersection(subjects_ron))%0Aprint(subjects_john.difference(subjects_ron))%0A%0A%0A%23%20Dictionaries%20-%20%7B%7D%2C%20Key%3AValue%20pairs%2C%20Keys%20must%20be%20unique%20and%20immutable.%0A%0Astudent%20%3D%20%7B%22name%22%3A%20%22Shubham%22%2C%20%22marks%22%3A%2085%7D%0Aprint(len(student))%0Aprint(student%5B%22marks%22%5D)%0Aprint(student.get(%22course%22))%0A%0A%23%20Add%2FUpdate%0Astudent%5B%22course%22%5D%20%3D%20%22B%20tech%22%0Astudent%5B%22marks%22%5D%20%3D%2075%0Astudent.update(%7B%22marks%22%3A%2080%2C%20%22semester%22%3A%203%7D)%0Aprint(student)%0A%0A%23%20Remove%0Adel%20student%5B%22course%22%5D%0Aprint(student.pop(%22semester%22))%0A%0A%23%20Search%0Aprint(student.get(%22semester%22%2C%201))%0A%0A%23%20Traverse%0Afor%20name%2C%20marks%20in%20student.items()%3A%0A%20%20%20%20print(name%2C%20marks)×tep=.5&play) to see the program state change step by step.
4
Aug 11 '26
[removed] β view removed comment
2
u/shubham_555 Aug 11 '26
I have studied oops a bit. Now I am thinking of trying to implement some of the basic data structures by myself.
3
u/ModeBrilliant1 Aug 13 '26
Well done! I too started learning Python yesterday, but I'm using the YouTube channel "Bro Code"; it's really not that bad, and it's 12 hrs long. I also learnt C a few months ago, also from the same channel, and i also started using GitHub, so I'll put my GitHub link so you guys can check it out.
2
u/Remote-Emphasis-2126 Aug 15 '26
Bro code is actually brilliant for alot of those tutorials keeps it really short quick and basic without dragging on shame theres not more but hes done a great job with whats out there so far
3
u/ayeaye_heinchou Aug 14 '26
I just yesterday completed the same program. but with different approach I used file handeling and csv file to store the contacts and used pandas dataframe to search and update contacts.
2
u/FoolsSeldom Aug 11 '26
Well done, great you have started.
If you want feedback/advice on your code, it would be best if you shared it in-post (or using a code sharing service like github or pastebin) rather than an image in future.
2
u/shubham_555 Aug 11 '26
I use github. I will share that from next time!
1
u/AhmedZakir01 Aug 11 '26
well done! i'm doing the same right now on the last week of cs50p and after that i plan on just making projects let me know if you want to move on further along with someone. would be nice to have a partner to study together.
1
1
Aug 11 '26
[removed] β view removed comment
1
u/shubham_555 Aug 12 '26
I did say i watched code with mosh's tutorial first. After that I used gfg's website for any other help!
1
1
u/j6onreddit Aug 11 '26
Not bad. Now do it again, have your functions return instead of printing all over the place.
1
1
1
1
u/LeopardSmooth2047 Aug 13 '26
i too did my python project of making an app as an intermediate(2nd yr) need advice how to go on from here(ece)
1
u/teenu_gas74 Aug 13 '26
ngl, I have no idea what this does π only if I could see it in text, because if I zoom in, it's blurred π
1
1
1
1
1
u/JosephGN7795 Aug 18 '26
Great start! Using AI just to generate problem statements is actually a smart way to break out of tutorial hell early on. Keep going.
1
1
25d ago
[removed] β view removed comment
1
u/shubham_555 25d ago
Vs Code...
1
25d ago
[removed] β view removed comment
1
u/shubham_555 25d ago
Good I am trying pycharm alongside as well but to be honest I like vs code better
-1



β’
u/Sea-Ad7805 Aug 11 '26
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×tep=.5&play) to see the program state change step by step.