This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-04-12 19:58:36

jji7skyline
Scratcher
Registered: 2010-03-08
Posts: 1000+

Learning Python

Can also be official topic  tongue

Anyways, I'm learning python from learnpython.org and I admit it's the best programming language I've tried so far! (Excluding Scratch obviously  wink  )

I'm kinda stuck with the strings and stuff.

What has %s and %d got to do with anything?  hmm

Last edited by jji7skyline (2012-04-12 19:58:44)


I don't know why you say goodbye, I say hello!  big_smile

Offline

 

#2 2012-04-12 20:18:29

samtwheels
Scratcher
Registered: 2011-03-20
Posts: 1000+

Re: Learning Python

There is a python official topic created by nickbrickmaster a while back. I'll try and find the link.

EDIT: Here it is.

Last edited by samtwheels (2012-04-12 20:20:51)

Offline

 

#3 2012-04-12 20:58:29

jji7skyline
Scratcher
Registered: 2010-03-08
Posts: 1000+

Re: Learning Python

samtwheels wrote:

There is a python official topic created by nickbrickmaster a while back. I'll try and find the link.

EDIT: Here it is.

There seems to be lots of python official topics  tongue


I don't know why you say goodbye, I say hello!  big_smile

Offline

 

#4 2012-04-12 21:54:51

samtwheels
Scratcher
Registered: 2011-03-20
Posts: 1000+

Re: Learning Python

jji7skyline wrote:

samtwheels wrote:

There is a python official topic created by nickbrickmaster a while back. I'll try and find the link.

EDIT: Here it is.

There seems to be lots of python official topics  tongue

There's this one, the one I made in misc, and the one above.

Offline

 

#5 2012-04-12 22:02:14

nickbrickmaster
Scratcher
Registered: 2010-02-02
Posts: 500+

Re: Learning Python

Python's great. You knew I would post here.
I think either %s or %d are used like this:

Code:

print("Your name is %s.", "Matt")

Ask me what I'm doing, wait an hour than roll a die, if it's 4-6, I'm playing Skyrim, if it's 1, I'm eating, if it's 2-3 I'm programming.
Steam: nickbrickmaster | RotMG: PwnThemAll | Minecraft: nickbrickmaster | League Of Legends: BaneOfTitans

Offline

 

#6 2012-04-12 23:33:53

CheeseMunchy
Scratcher
Registered: 2008-10-13
Posts: 1000+

Re: Learning Python

I was just messing around with it.


6418,

Offline

 

#7 2012-04-13 14:23:52

RedRocker227
Scratcher
Registered: 2011-10-26
Posts: 1000+

Re: Learning Python

I got it a couple of days ago (along with about five others), but I haven't even opened it yet.  tongue


Why

Offline

 

#8 2012-04-13 14:42:25

maxskywalker
Scratcher
Registered: 2008-01-27
Posts: 1000+

Re: Learning Python

The way that things like %s work, is you type %s somewhere in your string, and then after your closing quote you say % followed by what you want to replace the %s with.  For example, you could say print("Hello %s!" % "World"), and you would get "Hello World!".  The letter is for the type.  %s is string, %d is double (or decimal number), and I think that %i is integer (whole number).  Anyway, yeah, it's great.

Offline

 

#9 2012-04-13 15:29:50

AlSweigart
New Scratcher
Registered: 2012-04-13
Posts: 3

Re: Learning Python

%s is for when you want the value to be interpreted as a (s)tring, and %d is for when you want the value to be interpreted as a (d)ecimal integer.

Here's some examples:
>>> print('Hello %s' % ('Steve'))
Hello Steve
>>> print('Hello %s' % ('3.14'))
Hello 3.14
>>> print('Hello %s' % (3.14))
Hello 3.14

>>> print('Hello %d' % (3.14))
Hello 3
>>> print('Hello %d' % ('Steve'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: %d format: a number is required, not str
>>>

Have you tried "Invent Your Own Computer Games with Python" at http://inventwithpython.com?

Offline

 

#10 2012-07-18 21:43:26

jji7skyline
Scratcher
Registered: 2010-03-08
Posts: 1000+

Re: Learning Python

maxskywalker wrote:

The way that things like %s work, is you type %s somewhere in your string, and then after your closing quote you say % followed by what you want to replace the %s with.  For example, you could say print("Hello %s!" % "World"), and you would get "Hello World!".  The letter is for the type.  %s is string, %d is double (or decimal number), and I think that %i is integer (whole number).  Anyway, yeah, it's great.

Ah cool. Thanks. I should continue learning it  tongue


I don't know why you say goodbye, I say hello!  big_smile

Offline

 

#11 2012-07-18 22:27:32

maxskywalker
Scratcher
Registered: 2008-01-27
Posts: 1000+

Re: Learning Python

jji7skyline wrote:

maxskywalker wrote:

The way that things like %s work, is you type %s somewhere in your string, and then after your closing quote you say % followed by what you want to replace the %s with.  For example, you could say print("Hello %s!" % "World"), and you would get "Hello World!".  The letter is for the type.  %s is string, %d is double (or decimal number), and I think that %i is integer (whole number).  Anyway, yeah, it's great.

Ah cool. Thanks. I should continue learning it  tongue

Did it really take you that long to read this?  lol

Offline

 

#12 2012-07-18 23:10:26

CheeseMunchy
Scratcher
Registered: 2008-10-13
Posts: 1000+

Re: Learning Python

Well. this is a duplicate too. So, close this one and use this one?

Last edited by CheeseMunchy (2012-07-18 23:13:02)


6418,

Offline

 

#13 2012-07-19 05:01:06

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Learning Python

samtwheels wrote:

There is a python official topic created by nickbrickmaster a while back. I'll try and find the link.

EDIT: Here it is.

Since this is a duplicate, I'll close it.  Remember:  the Search button really helps prevent duplicates  smile


http://i39.tinypic.com/2nav6o7.gif

Offline

 

Board footer