Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How to type
Index -> Programming, Python -> Python Submissions
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
swami




PostPosted: Tue Apr 01, 2008 9:35 pm   Post subject: How to type

OK.. well since there is no other submissions, i want to be the first to submit something in python. I know Turing and a bit of Java but Python is very new to me. I actually just learned how to output words like 30 seconds ago. Basically i am doing this to be the first person to ever submit a topic in the Python Submissions.

So if you are familiar with Turing, in order to output something you would type:

put "example"

And if you know Java you would type:

public class example {
public static void main(String[] args) {
System.out.println("example");
}
}

Basically in both of these programs you are telling Java/Turing to output "example"

In Python, it is very similar to Turing with the 'put' statement. But instead of using 'put', we use 'print'

So if we wanted to output "example" in Python we would type:

print "example"

That's all I know for now... but in another 30 seconds ill learn more Very Happy
Sponsor
Sponsor
Sponsor
sponsor
andrew.




PostPosted: Thu Jun 19, 2008 10:59 am   Post subject: RE:How to type

Haha...I am also new to Python and to get information from the user (like get in Turing), you use:

Python:
name = raw_input ("What is your name? ")
Aziz




PostPosted: Thu Jun 19, 2008 11:21 am   Post subject: RE:How to type

I don't think it qualifies for a submission, the way you worded it is more like a tutorial, but congratulations on your first step into python!

Read more in the Python Tutorials section. Python isn't like programming in Turing or Java.

Also,

Turing:
code:
put "Hello, ", name


Python:
code:
print "Hello,", name


Notice the lack of a space in the quotes for Python. By default, python puts spaces in between outputs separated by "," in a print statement.
Insectoid




PostPosted: Thu Jun 19, 2008 1:01 pm   Post subject: RE:How to type

Hmm, that is nice to know! I really should get around to learning that...


How can you print to a separate window? That's one of the things I'd really like to know, as well as drawing in code, importing files/pictures/music, and mouse commands. Keyboard commands too.
apomb




PostPosted: Thu Jun 19, 2008 3:22 pm   Post subject: RE:How to type

python has a library for graphics, here's the link to some info and a download site for that library: PIL
Quote:
PIL (Python Imaging Library) it is the "standard" Python graphics library.
It is used to create images in the form of pictures and saving as .png, .jpg, or whatever.
Zeroth




PostPosted: Thu Jun 19, 2008 3:27 pm   Post subject: Re: How to type

Well, you can use a module called subprocess on python, to send data via a pipe to another shell or program. Look it up, its a bit obtuse however.

I typically use the pygame.mixer library to play music. And again, pygame for handling keyboard commands, unless I'm using a GUI framework, like wxPython. In that case, the framework itself handles keyboard commands for you, in most cases.
Insectoid




PostPosted: Thu Jun 19, 2008 4:36 pm   Post subject: RE:How to type

Will I NEED to have a text processor to run programs, or is there a way to make the command window not run as you type?

Here's a tiny, simple program that was on my exam in Turing that I am trying to convert to python to help me learn how it works.

The program inputs an item cost and adds 7% tax if the cost is higher than $4.

Python:

cost= raw_input ("Enter cost of item")
if cost > 4:
     cost= cost * 1.07

print "The total cost is", cost


Would I have to type this into a word processor with python syntax stuff, or is there a way to make the command line not run it until I tell it to?

Expect me to post dozens of questions over the summer!

Oh, I know it doesn't work; How do I convert int to real formant?
Insectoid




PostPosted: Thu Jun 19, 2008 5:19 pm   Post subject: RE:How to type

Revised!

Python:

while loop > 0:
     cost = raw_input ("Enter cost of item")
     cost = (int(cost))
     if cost > 4:
          cost *= 1.07
    print cost



Now to learn delays...
Sponsor
Sponsor
Sponsor
sponsor
shaon




PostPosted: Thu Jun 19, 2008 8:56 pm   Post subject: Re: RE:How to type

insectoid @ Thu Jun 19, 2008 4:36 pm wrote:
Will I NEED to have a text processor to run programs, or is there a way to make the command window not run as you type?

Here's a tiny, simple program that was on my exam in Turing that I am trying to convert to python to help me learn how it works.

The program inputs an item cost and adds 7% tax if the cost is higher than $4.

Python:

cost= raw_input ("Enter cost of item")
if cost > 4:
     cost= cost * 1.07

print "The total cost is", cost


Would I have to type this into a word processor with python syntax stuff, or is there a way to make the command line not run it until I tell it to?

Expect me to post dozens of questions over the summer!

I believe you need to use a text editor. If your using IDLE, just go to the file tab and click on new, and you can type your code then hit F5 to run it in the shell. Realistically, you can use any thing to type up python code as long as you save it with the extension ".py" it will work just fine. In fact you don't even need the run time command line. If you just double click your python file, it will run (but you won't be able to catch error statements since the windows closes very fast).

Oh, I know it doesn't work; How do I convert int to real formant?
shaon




PostPosted: Thu Jun 19, 2008 8:56 pm   Post subject: Re: RE:How to type

I believe you need to use a text editor. If your using IDLE, just go to the file tab and click on new, and you can type your code then hit F5 to run it in the shell. Realistically, you can use any thing to type up python code as long as you save it with the extension ".py" it will work just fine. In fact you don't even need the run time command line. If you just double click your python file, it will run (but you won't be able to catch error statements since the windows closes very fast).
Display posts from previous:   
   Index -> Programming, Python -> Python Submissions
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 10 Posts ]
Jump to:   


Style:  
Search: