Week #4 Challenge: Python

• (8 Pages)
• 1
• 2
• 3
• Last »

108 Replies - 30919 Views - Last Post: 06 September 2011 - 12:05 PM

#1 SixOfEleven

• Planeswalker

Reputation: 1055
• Posts: 6,643
• Joined: 18-October 08

Week #4 Challenge: Python

Posted 25 January 2010 - 05:57 AM

Week #4: Python

Challenge: Write a simple program using Python.

What is Python?

Python is a remarkably powerful dynamic programming language that is used in a wide variety of application domains. Python is often compared to Tcl, Perl, Ruby, Scheme or Java. Some of its key distinguishing features include:
• strong introspection capabilities
• intuitive object orientation
• natural expression of procedural code
• full modularity, supporting hierarchical packages
• exception-based error handling
• very high level dynamic data types
• extensive standard libraries and third party modules for virtually every task
• extensions and modules easily written in C, C++ (or Java for Jython, or .NET languages for IronPython)
• embeddable within applications as a scripting interface

This is a simple script I wrote to calculate the first 16 powers of 2 including 0.
```a = 0
b = 1
while a < 17:
print b,
a, b = a + 1, b * 2

```

In the print statement having the comma after b causes the next item printed to be on the same line. This line of code a, b = a + 1, b * 2 is a multiple assignment that assigns a + 1 to a and b * 2 to b.

This code snippet form KYA will sort a list.
```# Bubble Sort
# KYA
# 7-20-08
def bubbleSort(theList, max):
for n in range(0,max): #upper limit varies based on size of the list
temp = 0
for i in range(1, max): #keep this for bounds purposes
temp = theList[i]
if theList[i] < theList[i-1]:
theList[i] = theList[i-1]
theList[i-1] = temp

```

Ideas:
For those of you who don't know what to do with Python, here's some ideas:
• A number guessing game
• Printing out the roll of dice
• Create a random password generator that generates a password with a certain number of letters and numbers
• A file handler that does something useful (such as remove executable properties on all files in the parent directory and below)
• Advanced - Create a simple game demo using pygame

Resources:
We also have a Perl & Python forum and Snippets area as well as a couple Python Tutorials if you're interested.

How To Get Started:
Installing python on windows is no harder than installing any other piece of software, go to http://python.org/download/ and get the appropriate package. On linux it's likely already included, but python3 will need to be installed explicitly, most distros have a package named "python3", so go ahead and grab that (source is always available if you run an odd-ball distro). If you need help, just ask google.

Getting Help:
Post questions in our Perl & Python Forum.

Is This A Good Question/Topic? 0

Replies To: Week #4 Challenge: Python

#2 carltech

• What did you call me?

Reputation: 28
• Posts: 997
• Joined: 19-October 07

Re: Week #4 Challenge: Python

Posted 25 January 2010 - 06:04 AM

maybe I'll put my python skills to the test on this one and make a game...I think I still have pygame on my desktop.
It has been a while since I used python though.

#3 SixOfEleven

• Planeswalker

Reputation: 1055
• Posts: 6,643
• Joined: 18-October 08

Re: Week #4 Challenge: Python

Posted 25 January 2010 - 06:06 AM

Then this is a great reason to try it again carltech. I look forward to seeing something from you.

#4 Skaggles

• THE PEN IS MIGHTIER

Reputation: 255
• Posts: 641
• Joined: 01-March 09

Re: Week #4 Challenge: Python

Posted 25 January 2010 - 06:27 AM

I know nothing about Python, so this would be a nice chance to check it out.

#5 SixOfEleven

• Planeswalker

Reputation: 1055
• Posts: 6,643
• Joined: 18-October 08

Re: Week #4 Challenge: Python

Posted 25 January 2010 - 06:30 AM

That's the spirit Skaggles! We are hoping for people to try things they have never worked with before. Until last week I had never tried Python either. So far I like it.

#6 baavgai

• Dreaming Coder

Reputation: 7507
• Posts: 15,558
• Joined: 16-October 07

Re: Week #4 Challenge: Python

Posted 25 January 2010 - 06:51 AM

Hmm... I never got around to the twitter one. Can I combine the two?

#7 skyhawk133

Reputation: 1972
• Posts: 20,425
• Joined: 17-March 01

Re: Week #4 Challenge: Python

Posted 25 January 2010 - 07:04 AM

Absolutely If you can figure out how to combine python, jquery, and twitter you can do all 3

#8 Shane Hudson

• D.I.C Technophile

Reputation: 345
• Posts: 1,286
• Joined: 06-December 09

Re: Week #4 Challenge: Python

Posted 25 January 2010 - 07:32 AM

Python? I remember using that when I was like.. 8 or something! I expect it has completely changed since then though, like all of the other languages have.

#9 Chris Coneybeer

Reputation: 0
• Posts: 8
• Joined: 30-October 07

Re: Week #4 Challenge: Python

Posted 25 January 2010 - 08:31 AM

So no never used python. Going to give the quick dice thing a go tonight. Been playing farkle lately and maybe create a quick game.

#10 SixOfEleven

• Planeswalker

Reputation: 1055
• Posts: 6,643
• Joined: 18-October 08

Re: Week #4 Challenge: Python

Posted 25 January 2010 - 08:34 AM

Sounds good Shane and Chris. I look forward to seeing something from you.

#11 TheStuff

Reputation: 1
• Posts: 48
• Joined: 16-April 09

Re: Week #4 Challenge: Python

Posted 25 January 2010 - 08:38 AM

OOOH. Nice. I've never actually done anything in Python, yet I have been very interested in it for a while. It was my alternative choice to C++ when I began, but I stuck with C++. Definitely giving this a shot.

2:30 AM here and school is starting soon so I guess I will start tomorrow.

This post has been edited by TheStuff: 25 January 2010 - 08:38 AM

#12 SixOfEleven

• Planeswalker

Reputation: 1055
• Posts: 6,643
• Joined: 18-October 08

Re: Week #4 Challenge: Python

Posted 25 January 2010 - 08:46 AM

Good to hear TheStuff. Look forward to seeing something from you.

#13 brianarn

Reputation: 11
• Posts: 27
• Joined: 02-October 09

Re: Week #4 Challenge: Python

Posted 25 January 2010 - 09:24 AM

I've been meaning to learn a little Python - I even have Dive Into Python 3 by Mark Pilgrim (an amazing author) and was planning on reading through the book this week, so, this lines up nicely.

Suggestion in general: If you want to learn a language but don't really have a specific project, picking something off of http://projecteuler.net/ is a great way to learn. Project Euler is neat.

#14 tashe

Reputation: 0
• Posts: 107
• Joined: 10-March 09

Re: Week #4 Challenge: Python

Posted 25 January 2010 - 09:39 AM

I like that it doesn't use curly braces like in Java or C++. It improves the readability so much.
Will definitely post something until the end of the week.

#15 UrbanTwitch

Reputation: 9
• Posts: 233
• Joined: 27-September 09

Re: Week #4 Challenge: Python

Posted 25 January 2010 - 10:43 AM

Hm. I barely know Python so this is going to be a good read. I may post something this week.

Thanks!!