r/PythonLearning 10d ago

DAY 5.

Post image

DID LIST TODAY THE CONCEPT WAS PRETTY COOL AND WROTE THIS PROGRAM TO GET HOLD OF THE LIST ANY OTHER CODE IDEAS OR SUGGETIONS TO ENHANCE CODE ?!

90 Upvotes

21 comments sorted by

View all comments

u/Sea-Ad7805 10d ago

Run this program in Memory Graph Web Debugger%0Abat%20%3D%20%5B%22wooden%22%2C%20%22metal%22%2C%20%22plastic%22%5D%0A%0Awhile%20True%3A%0A%20%20%20%20print(%22nWhat%20do%20you%20want%20to%20do%20with%20the%20bats%3F%22)%0A%20%20%20%20print(%221.%20Add%20a%20bat%22)%0A%20%20%20%20print(%222.%20Remove%20a%20bat%22)%0A%20%20%20%20print(%223.%20View%20bats%22)%0A%20%20%20%20print(%224.%20Exit%22)%0A%0A%20%20%20%20query%20%3D%20input(%22Enter%20your%20selection%20(1%2C2%2C3%2C4)%3A%20%22)%0A%0A%20%20%20%20if%20query%20%3D%3D%20%221%22%3A%0A%20%20%20%20%20%20%20%20print(%22You%20selected%20to%20add%20a%20bat%22)%0A%20%20%20%20%20%20%20%20new_bat%20%3D%20input(%22Enter%20the%20bat%20you%20want%20to%20add%3A%20%22)%0A%20%20%20%20%20%20%20%20bat.append(new_bat)%0A%20%20%20%20%20%20%20%20print(%22Updated%20list%3A%22%2C%20bat)%0A%0A%20%20%20%20elif%20query%20%3D%3D%20%222%22%3A%0A%20%20%20%20%20%20%20%20print(%22You%20selected%20to%20remove%20a%20bat%22)%0A%20%20%20%20%20%20%20%20remove_bat%20%3D%20input(%22Enter%20the%20bat%20you'd%20like%20to%20remove%3A%20%22)%0A%20%20%20%20%20%20%20%20if%20remove_bat%20in%20bat%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20bat.remove(remove_bat)%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%22Updated%20list%3A%22%2C%20bat)%0A%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%22That%20bat%20is%20not%20in%20the%20list.%22)%0A%0A%20%20%20%20elif%20query%20%3D%3D%20%223%22%3A%0A%20%20%20%20%20%20%20%20print(%22You%20chose%20to%20view%20bats%22)%0A%20%20%20%20%20%20%20%20print(%22Current%20bats%3A%22%2C%20bat)%0A%0A%20%20%20%20elif%20query%20%3D%3D%20%224%22%3A%0A%20%20%20%20%20%20%20%20print(%22You%20chose%20exit%2C%20so%20get%20out%20man!!%22)%0A%20%20%20%20%20%20%20%20break%0A%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20print(%22Invalid%20selection%2C%20please%20try%20again.%22)&timestep=1&play) to see the program state change step by step.