Discuss Scratch

17camps
Scratcher
3 posts

Python programming language

Hi! Python is great! I've just programmed Pong on Pygame, following the Hello World! Programming for Kids and Other Beginners' example.
17camps
Scratcher
3 posts

Python programming language

Hi! Python is great! I've just programmed Pong on Pygame, following the Hello World! Programming for Kids and Other Beginners' example.
amgames
New to Scratch
100+ posts

Python programming language

alebovic wrote:

print ‘oh why sure I use python’
import turtle
t=turtle.pen()
t.forward(90).
I think scratch really helped me understand some turtle concepts like if, else, and, or, and such so.
It's nice to see turtle in use, though it's usually better to use tk

Magnie hasn't posted here yet…?!

amgames
programmer ~ artist in training ~ pianist
davidkt
Scratcher
1000+ posts

Python programming language

I'm pretty much a Python pro, I learned it when I was 9.

Remember when I looked like this? I still do.


Float, my Scratch 2.0 mod | My (somewhat under-construction) blog
RoboNeo9
Scratcher
96 posts

Python programming language

This is how you create 32 digit “variables” in a purely 8bit system:
sbin turns your base ten number into the special “binary” code (it isn't realy binary, it is by digit). It works for up to 32 digit numbers
sdec turns your special “binary” number into a base ten number (MUST BE STRING)
smbin multiplies two numbers that you input (input has to be the special binary). It multiplies digit by digit with correct place value and remainder
smdec is the same as smbin but the input is a base 10 number
This is a module and you must import all functions or some of the functions wont work!
This would work on an NES even though an NES variable can not exceed 255

def sbin(x):
number=str(x)
a=“ ”
b=“ ”
c=“ ”
d=“ ”
e=“ ”
f=“ ”
g=“ ”
h=“ ”
i=“ ”
j=“ ”
k=“ ”
l=“ ”
m=“ ”
n=“ ”
o=“ ”
p=“ ”
z=0
if len(number)%2==0:
while z!=len(number):
if z==0:
a=“0”*(4-(len(bin(int(number)))))+bin(int(number))+“0”*(4-(len(bin(int(number)))))+bin(int(number))
if z==2:
b=“0”*(4-(len(bin(int(number)))))+bin(int(number))+“0”*(4-(len(bin(int(number)))))+bin(int(number))
if z==4:
c=“0”*(4-(len(bin(int(number)))))+bin(int(number))+“0”*(4-(len(bin(int(number)))))+bin(int(number))
if z==6:
d=“0”*(4-(len(bin(int(number)))))+bin(int(number))+“0”*(4-(len(bin(int(number)))))+bin(int(number))
if z==8:
e=“0”*(4-(len(bin(int(number)))))+bin(int(number))+“0”*(4-(len(bin(int(number)))))+bin(int(number))
if z==10:
f=“0”*(4-(len(bin(int(number)))))+bin(int(number))+“0”*(4-(len(bin(int(number)))))+bin(int(number))
if z==12:
g=“0”*(4-(len(bin(int(number)))))+bin(int(number))+“0”*(4-(len(bin(int(number)))))+bin(int(number))
if z==14:
h=“0”*(4-(len(bin(int(number)))))+bin(int(number))+“0”*(4-(len(bin(int(number)))))+bin(int(number))
if z==16:
i=“0”*(4-(len(bin(int(number)))))+bin(int(number))+“0”*(4-(len(bin(int(number)))))+bin(int(number))
if z==18:
j=“0”*(4-(len(bin(int(number)))))+bin(int(number))+“0”*(4-(len(bin(int(number)))))+bin(int(number))
if z==20:
k=“0”*(4-(len(bin(int(number)))))+bin(int(number))+“0”*(4-(len(bin(int(number)))))+bin(int(number))
if z==22:
l=“0”*(4-(len(bin(int(number)))))+bin(int(number))+“0”*(4-(len(bin(int(number)))))+bin(int(number))
if z==24:
m=“0”*(4-(len(bin(int(number)))))+bin(int(number))+“0”*(4-(len(bin(int(number)))))+bin(int(number))
if z==26:
n=“0”*(4-(len(bin(int(number)))))+bin(int(number))+“0”*(4-(len(bin(int(number)))))+bin(int(number))
if z==28:
o=“0”*(4-(len(bin(int(number)))))+bin(int(number))+“0”*(4-(len(bin(int(number)))))+bin(int(number))
if z==30:
p=“0”*(4-(len(bin(int(number)))))+bin(int(number))+“0”*(4-(len(bin(int(number)))))+bin(int(number))
z=z+2
else:
z=-1
while z!=len(number):
if z==-1:
a=“0”*4+“0”*(4-(len(bin(int(number)))))+bin(int(number))
if z==1:
b=“0”*(4-(len(bin(int(number)))))+bin(int(number))+“0”*(4-(len(bin(int(number)))))+bin(int(number))
if z==3:
c=“0”*(4-(len(bin(int(number)))))+bin(int(number))+“0”*(4-(len(bin(int(number)))))+bin(int(number))
if z==5:
d=“0”*(4-(len(bin(int(number)))))+bin(int(number))+“0”*(4-(len(bin(int(number)))))+bin(int(number))
if z==7:
e=“0”*(4-(len(bin(int(number)))))+bin(int(number))+“0”*(4-(len(bin(int(number)))))+bin(int(number))
if z==9:
f=“0”*(4-(len(bin(int(number)))))+bin(int(number))+“0”*(4-(len(bin(int(number)))))+bin(int(number))
if z==11:
g=“0”*(4-(len(bin(int(number)))))+bin(int(number))+“0”*(4-(len(bin(int(number)))))+bin(int(number))
if z==13:
h=“0”*(4-(len(bin(int(number)))))+bin(int(number))+“0”*(4-(len(bin(int(number)))))+bin(int(number))
if z==15:
i=“0”*(4-(len(bin(int(number)))))+bin(int(number))+“0”*(4-(len(bin(int(number)))))+bin(int(number))
if z==17:
j=“0”*(4-(len(bin(int(number)))))+bin(int(number))+“0”*(4-(len(bin(int(number)))))+bin(int(number))
if z==19:
k=“0”*(4-(len(bin(int(number)))))+bin(int(number))+“0”*(4-(len(bin(int(number)))))+bin(int(number))
if z==21:
l=“0”*(4-(len(bin(int(number)))))+bin(int(number))+“0”*(4-(len(bin(int(number)))))+bin(int(number))
if z==23:
m=“0”*(4-(len(bin(int(number)))))+bin(int(number))+“0”*(4-(len(bin(int(number)))))+bin(int(number))
if z==25:
n=“0”*(4-(len(bin(int(number)))))+bin(int(number))+“0”*(4-(len(bin(int(number)))))+bin(int(number))
if z==27:
o=“0”*(4-(len(bin(int(number)))))+bin(int(number))+“0”*(4-(len(bin(int(number)))))+bin(int(number))
if z==29:
p=“0”*(4-(len(bin(int(number)))))+bin(int(number))+“0”*(4-(len(bin(int(number)))))+bin(int(number))
z=z+2
answer=“0”*(4-((len(str(int(a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p)))%4)))+str(int(a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p))
return answer;
def sdec(x):
z=0
a=“”
while z!=len(x):
a=a+str(int(str(x)+str(x)+str(x)+str(x),2))
z=z+4
return a;
def smbin(x,y):
L=list()
a=sdec(x)
k=0
while k!=len(a):
L.append(a)
k=k+1
k=0
M=list()
b=sdec(y)
while k!=len(b):
M.append(b)
k=k+1
i=len(b)-1
k=len(a)-1
S=list()
z=“”
rem=0
t=0
while i!=-1:
while k!=-1:
z=str(((int(a)*int(b))+rem)%(10**1))+z
rem=(int(((int(a)*int(b)+int(rem))-(((int(a)*int(b)+int(rem))%(10)))))/10)
k=k-1
z=str(int(str(rem)+z)*(10**t))
rem=0
i=i-1
t=t+1
S.append(int(z))
k=len(a)-1
z=“”
v=sum(S)
ans=sbin(str(v))
return ans;
def smdec(x,y):
L=list()
a=str(x)
k=0
while k!=len(a):
L.append(a)
k=k+1
k=0
M=list()
b=str(y)
while k!=len(b):
M.append(b)
k=k+1
i=len(b)-1
k=len(a)-1
S=list()
z=“”
rem=0
t=0
while i!=-1:
while k!=-1:
z=str(((int(a)*int(b))+rem)%(10**1))+z
rem=(int(((int(a)*int(b)+int(rem))-(((int(a)*int(b)+int(rem))%(10)))))/10)
k=k-1
z=str(int(str(rem)+z)*(10**t))
rem=0
i=i-1
t=t+1
S.append(int(z))
k=len(a)-1
z=“”
v=sum(S)
ans=sbin(str(v))
return ans;

Broken pencils are pointless…
Rumanti
Scratcher
1000+ posts

Python programming language

I was about to make a Python thread, but luckily I found this on my search.

Python is awesome! I am currently doing Programming for Everybody course on Coursera. It teaches Python. I am addicted to Python since then.

Also, this is one of my Python project. It flips text backward, just like my newest project, Flip That Text. (For your info, Flip That Text is actually based on the Python version)

plain_text = raw_input("Text to flip backwards : ")

char_counter = 0
char = None
result = None

while True:
while True:
char_counter = char_counter - 1
char = plain_text[char_counter]
if result is None:
result = char
else:
result = result + char
if len(result) == len(plain_text):
break

print result
x = raw_input("> ")
if x == "done":
break

And a question: (from a newbie )
How do you generate random numbers? I think I read about it somewhere but I didn't remember where.
Can someone help?

Last edited by Rumanti (July 8, 2014 13:25:44)


:wq
amgames
New to Scratch
100+ posts

Python programming language

Rumanti wrote:

I was about to make a Python thread, but luckily I found this on my search.

Python is awesome! I am currently doing Programming for Everybody course on Coursera. It teaches Python. I am addicted to Python since then.

Also, this is one of my Python project. It flips text backward, just like my newest project, Flip That Text. (For your info, Flip That Text is actually based on the Python version)

plain_text = raw_input("Text to flip backwards : ")

char_counter = 0
char = None
result = None

while True:
while True:
char_counter = char_counter - 1
char = plain_text[char_counter]
if result is None:
result = char
else:
result = result + char
if len(result) == len(plain_text):
break

print result
x = raw_input("> ")
if x == "done":
break

And a question: (from a newbie )
How do you generate random numbers? I think I read about it somewhere but I didn't remember where.
Can someone help?
Cool stuff! Reversing text can also be done with slices– lemme do a mini tutorial.

Slicing lets you access an element of an iterable (fancy name for lists or tuples) or string, as in your code;

>>> x = "text"
>>> x[0]
't'
>>> x[1]
'e'
>>> x = ["hi!", "wow!"]
>>> x[0]
'hi!'
>>> x[0][0]
'h'

The slicing syntax can take multiple arguments separated by a colon, to give you a range from the first argument (inclusive) to the last (exclusive);

>>> x = "this is an example string"
>>> x[0:5]
'this '
>>> x = ["abc", "def", "ghi"]
>>> x[1:3]
['def', 'ghi']

Either of these can be left out and default to 0 and the length of the object, respectively;

>>> x = "this is an example string"
>>> x[:5]
'this '
>>> x = ["abc", "def", "ghi"]
>>> x[1:]
['def', 'ghi']

There is also a third argument, step, which defaults to 1; it's how much to change the counter for every new character. It's best to explain in code;

def slice(string, start = 0, end = ' ', step = 1):
    if end == ' ':
        end = len(string)
    if step < 0:
        start, end = end, start
    out = ""
    while start < end:
        out += string[start]
        start += step
    return(out)

(pretty dirty code, but yeah.)

Thus, a string can be reversed like this;

string = string[::-1]

As for your question on random numbers; (copied from python docs)

>>> import random
>>> random.random() # Random float x, 0.0 <= x < 1.0
0.37444887175646646
>>> random.uniform(1, 10) # Random float x, 1.0 <= x < 10.0
1.1800146073117523
>>> random.randint(1, 10) # Integer from 1 to 10, endpoints included
7
>>> random.randrange(0, 101, 2) # Even integer from 0 to 100
26
>>> random.choice('abcdefghij') # Choose a random element
'c'

amgames
programmer ~ artist in training ~ pianist
amgames
New to Scratch
100+ posts

Python programming language

amgames wrote:

def slice(string, start = 0, end = ' ', step = 1):
    if end == ' ':
        end = len(string)
    if step < 0:
        start, end = end, start
    out = ""
    while start < end:
        out += string[start]
        start += step
    return(out)
Woah, woah! I forgot to xor the condition with step's cmp. *facepalm*

while (start < end) ^ (step < 0):

sorry for the double post

amgames
programmer ~ artist in training ~ pianist
Rumanti
Scratcher
1000+ posts

Python programming language

Thanks for the tutorial, amgames. It's interesting to see new Python codes.

I have been trying out random.randint for ages and it gave me an error everytime. Now, I realized that the secret is
>>> import random
Lol. Now my code will work. Thanks for telling me

:wq
cardinalland
Scratcher
100+ posts

Python programming language

I am about to start learning python.

move (1000000000000000000000000000000) steps
Check out this link if you like games!

amgames
New to Scratch
100+ posts

Python programming language

Rumanti wrote:

Thanks for the tutorial, amgames. It's interesting to see new Python codes.

I have been trying out random.randint for ages and it gave me an error everytime. Now, I realized that the secret is
>>> import random
Lol. Now my code will work. Thanks for telling me
Heheh

cardinalland wrote:

I am about to start learning python.
Yaaaaaay ;D Just a thing to keep in mind, Python doesn't care about what types of objects you put into variables but other languages do, so avoid changing the type of a variable. It'll be a bit easier to transition to, say, Java, if you do
Also, other languages have huge standard libraries compared to Python, so you might wanna try memorizing most (or all) of it over the course of a few months and try to write some code with each different module. Great for when you're coding and have no internet connection.

amgames
programmer ~ artist in training ~ pianist
Rumanti
Scratcher
1000+ posts

Python programming language

Here's a neat website for practicing your Python skills. (beginner)

http://www.reddit.com/r/beginnerprojects

:wq
astro-mechanic
Scratcher
500+ posts

Python programming language

Rumanti wrote:

Here's a neat website for practicing your Python skills. (beginner)

http://www.reddit.com/r/beginnerprojects
Reddit is awesome.

I really wanna take on a nice big Python project with somebody from the ATs, when I'm done with my current projects of course (and assuming anybody'd put up with my strangeness).

sign here
emperor of shiny things
AonymousGuy
Scratcher
1000+ posts

Python programming language

I uh… really don't like the syntax in Python.

It makes me cry.
MrFlash67
Scratcher
500+ posts

Python programming language

AonymousGuy wrote:

I uh… really don't like the syntax in Python.

It makes me cry.
I don't like the syntax in anything but Python.

It makes me pull my hair out and cry.

like tears in chocolate rain
(2012 - 2022 - 20XX)
turkey3
Scratcher
1000+ posts

Python programming language

MrFlash67 wrote:

AonymousGuy wrote:

I uh… really don't like the syntax in Python.

It makes me cry.
I don't like the syntax in anything but Python.

It makes me pull my hair out and cry.
Same! I don't like how you don't need semicolons, don't have to declare variables, and don't need parenthesis after an “if” statement.

Firedrake969
Scratcher
1000+ posts

Python programming language

turkey3 wrote:

MrFlash67 wrote:

AonymousGuy wrote:

I uh… really don't like the syntax in Python.

It makes me cry.
I don't like the syntax in anything but Python.

It makes me pull my hair out and cry.
Same! I don't like how you don't need semicolons, don't have to declare variables, and don't need parenthesis after an “if” statement.
JavaScript is so much more readable than Python to me.

'17 rickoid

bf97b44a7fbd33db070f6ade2b7dc549
AonymousGuy
Scratcher
1000+ posts

Python programming language

turkey3 wrote:

MrFlash67 wrote:

AonymousGuy wrote:

I uh… really don't like the syntax in Python.

It makes me cry.
I don't like the syntax in anything but Python.

It makes me pull my hair out and cry.
Same! I don't like how you don't need semicolons, don't have to declare variables, and don't need parenthesis after an “if” statement.
The main problem I have is this:

WHY WOULD YOU EVER MAKE AN IF STATEMENT RELY ON WHITESPACE TO KNOW WHAT CODE IT WERE TO RUN???

Okay. I'm going to calm down now. Hopefully.
amgames
New to Scratch
100+ posts

Python programming language

For the guys hating on Python's syntax choices.

Sometimes people design languages just to get a concept out there, so other people can refine it and advance the programming field. Python was one of these languages, except the people refining the concept turned out to be the Python community.

If you don't like Python's syntax, then you don't like programming using Python. Just use something else. Python wasn't made to be a good C clone.

amgames
programmer ~ artist in training ~ pianist
fission
Scratcher
57 posts

Python programming language

AonymousGuy wrote:

WHY WOULD YOU EVER MAKE AN IF STATEMENT RELY ON WHITESPACE TO KNOW WHAT CODE IT WERE TO RUN???
Something tells me you wouldn't like this language. Note that the text in the examples is not the code. To see the code, you need to highlight the page.

Last edited by fission (July 18, 2014 18:15:31)


Christiaan Huygens is my arch-nemesis!

Powered by DjangoBB