Post AV9rILk6O2YNUkrQQK by PizzaRollSmoothie@freespeechextremist.com
(DIR) More posts by PizzaRollSmoothie@freespeechextremist.com
(DIR) Post #AV9jRFpYwAbs8H9M7k by warmbeverageenjoyer@freespeechextremist.com
2023-04-29T20:59:27.969999Z
1 likes, 0 repeats
packing? nofiguring out how to code 99 Bottles of Beer in Python? yesi did it :)i'm sure there are better/more efficient ways of doing itbut with the limited knowledge I have, it is what it is. It works, loops 3 times, then prints how many times it looped and says something about being an alcoholic, haha
(DIR) Post #AV9rILk6O2YNUkrQQK by PizzaRollSmoothie@freespeechextremist.com
2023-04-29T22:27:29.821663Z
1 likes, 0 repeats
@warmbeverageenjoyer Post that code! I wanna see it
(DIR) Post #AV9t2e0CvgmHOy25fE by warmbeverageenjoyer@freespeechextremist.com
2023-04-29T22:47:04.116905Z
0 likes, 0 repeats
@PizzaRollSmoothie Sure, why not. Absolutely open to hear any input you have, too! Just keep in mind that I have pretty much 0 experience programming anything lololcount = 0while count < 3: bottles = 99 while bottles > 2: print(bottles, "of beer on the wall,", bottles, "bottles of beer.\n" "Take one down and pass it around,", bottles - 1, "bottles of beer on the wall.") bottles -= 1 if bottles == 2: print(bottles, "of beer on the wall,", bottles, "bottles of beer.\n" "Take one down and pass it around,", "1 bottle of beer on the wall.") bottles -= 1 if bottles == 1: print(bottles, "of beer on the wall,", bottles, "bottle of beer.\n" "Take one down and pass it around, no more bottles of beer on the wall.") print("Go to the store and buy some more, 99 bottles of beer on the wall.") count += 1print("WE SANG THAT SHIT", count, "TIMES. WE ALCOHOLICS UP IN HURR.")
(DIR) Post #AVA3GcJ320mljl994S by PizzaRollSmoothie@freespeechextremist.com
2023-04-30T00:41:38.647104Z
1 likes, 0 repeats
@warmbeverageenjoyerVery nice! I used to be a java dev by trade.You should try this same exercise but instead of using 'while' loops, try and use 'for' loops
(DIR) Post #AVA63j2UzDuOiWwytE by SmoothOperator@freespeechextremist.com
2023-04-30T01:12:55.762173Z
1 likes, 0 repeats
Consider reading the desired count from sys.argv or by prompting the user, if you don't know how to do that yet. Otherwise, the final count would just be 99*3 and you can elide that variable to simplify the code. (Never forget: simpler means less shit can go wrong!)You could also try to reduce the duplication of the text using "string formatters":def printbeer(n):b = 'bottle' if n == 1 else 'bottles'print(f'{n} {b} of beer on the wall, {n} {b} of beer')The rosettacode page on this problem has a lot of stuff you could try:https://rosettacode.org/wiki/99_Bottles_of_Beer#Python
(DIR) Post #AVABVgFPSX8rwD8eWG by warmbeverageenjoyer@freespeechextremist.com
2023-04-30T02:14:00.398234Z
0 likes, 0 repeats
@PizzaRollSmoothie ty~i'm going to keep coming back to it as I learn more to try to make it more efficient and elegant
(DIR) Post #AVABd3x9ikfzUE7Xea by warmbeverageenjoyer@freespeechextremist.com
2023-04-30T02:15:20.451671Z
1 likes, 0 repeats
@SmoothOperator Thanks for the tips + link! I haven't learned about pretty much any of that stuff yet, but I look forward to coming back to the exercise over and over as I learn stuff to make it simpler and more efficient