Open TheHockeyist opened 7 years ago
Does the code work? I think it works, but I'm not printing everything to make sure.
Traceback (most recent call last):
File "python", line 4
set bottles = 99
^
SyntaxError: invalid syntax
In both python 2.7 and python 3.
BTW: Nice to see you again
Workarounded it.
EDIT: Okay, I think I probably fixed it.
You need to commit for me to view it. Also it seems like the repeat code is broken. I'm not a python expert though
Ah, okay.
Any other people want to help me out here?
@theinitializer codes in python
Ah, okay. Not sure if he knows that we exist here, but I could use a bit of help.
I mentioned him
Okay.
Question: Why did you leave scratch again?
Project got remixed, disputed it with the creator, creator refused to delete it, took it to the ST.
Then while talking, there was a dispute with the ST. Nothing I could do.
Infuriated, I reassessed why I came to Scratch and if the community was the same as it was when I joined. It became more immature, I concluded Scratch was insufficient for my needs, and I left.
ok
Hello, what is this? I got mentioned.
Is there anything you need help with?
Yeah, I need some help with coding this. I'm not sure if my code works or not.
EDIT: Typo.
set
has nothing to do with setting variables in Python==
is for comparison, and =
is for setting variables.repeat X
is not valid in Python - you want to do for i in range(X)
print
requires commas between things (or you could combine them with the +
operator)Haha.
Well - not sure how else to say this - it's all wrong. None of that is valid Python (aside from the first two lines, lol).
I'd advise you take a quick Python tutorial and learn how it works before writing any serious code 😛
Since people are raiding this thread and talking about how not-Python the code is.. I recommend you learn to use IDLE so you can test your code as you're working on it, and also GitHub Desktop, so you can actually commit your code and make that code appear online (or git, if you're cool and used to the command line).
You'll find it a lot more useful in the long run when you start working on bigger projects.
I attempted to somewhat Python-ize the code.
I'm coming from Scratch, so some of the syntax is still unfamiliar.
Again, set
has nothing to do with variable assignment. You should probably read the syntax docs and frequently refer to them as you write this
Reattempted.
Yeah, I have no idea what I'm doing. :-/.
It'll probably be more useful to, you know, actually learn Python before making anything with it, as opposed to just trying to guess what to do :P
Well, it's my first time really coding something independently in Python.
We all have to start somewhere.
And the best place to start is to:
learn Python before making anything with it, as opposed to just trying to guess what to do :P
Er, learn the basics of Python before making anything with it. Just enough to open up IDLE and see some real results on your screen – you know, just learn how to use the print
statement or function and see the result. Then move on from there. The whole "see it on your screen" part is.. really, really important.. :tada:
edit: is it not more fun to see the results on your screen, as you're programming the code that makes those results? :)
Good advice. I think you should try to learn Py 3 not 2, though. https://docs.python.org/3/tutorial/
@TheInitializer Are you ignoring me?
@Blaze349 is correct, there's really not much of a reason to stick with Python 2 anymore. Python 3 is the way to go at this point.
@Blaze349 wdym
@TheInitializer legacy (or "legacy") code that's a pain to port
I doubt OP will be working with much of that though
@TheInitializer nvm
@Firedrake969 That isn't much of a reason. Its like saying we should stick to Assembly because its too much hard work to port the legacy code to C.
@Blaze349 I'm going with the assumption that legacy code really does exist for Python 2, though. Nobody uses code made in Assembly, but a lot of people used Python 2 code which makes Py2 kinda just stick around. (..this is just an assumption, please correct me, somebody who knows better..)
@liam4 People used to use assembly for everything. People should move to Py 3. I don't see the benefits of going with Py 2.
@liam4 Your assumption is correct - I have experience with one. (also @Blaze349 for this next part)
Python 3 is the way to go for new projects, sure, but plenty of old/existing projects are in Python 2, and it's not like there are huge differences. Also, it can be a pain to port large projects... making sure everything still works the exact same way and stuff, for a few hundred thousand users
It's not like that's a magic solution if you're using multiple libraries and have a lot of things that could potentially break
Wait, so why are we arguing over if my (poorly written) code is Python 2 or 3?
I JUST WANT MY CODE TO WORK, JEEZ!!!
@TheHockeyist If you want your code to work then follow liam4's instructions. Read the documentation and work through the examples.
Is there a cheat sheet or something?
Yes. Its called documentation
I don't know of any good, quick-and-easy cheat sheets. You'll probably get the hang of the basics of programming with Python (that is, making programs that run 😛 ) pretty quickly. If you find yourself forgetting a specific piece of code a lot - for example, how to loop a number of times - you could write yourself a cheat sheet!
Well, the while loop works now. Not sure how to print.
Okay, I think I fixed the thing.
I've heard a lot of variants of the song. Some people start with 100 or some start with 99.
The beverage varies depending on the version. I learned it as milk (e.g. I sing "99 bottles of milk on the wall"...) but traditionally, it's an alcoholic beverage that many people would rather not have their children singing about. So I decided to include an option for choosing your beverage of choice.
The third line also varies, from "Take one down, pass it around" to "If one of those bottles should happen to fall".
And lastly, what happens when we reach zero?
0 bottles of milk on the wall, 0 bottles of milk. Go to the store and buy some more, 99 bottles of milk on the wall!
That's how I learned it.