Python

I am learning a powerful programming language, Python. Python is a powerful, object oriented scripting language, which is capable to do incredible things with few lines of code. Python currently runs on many platforms, but its native platform is and will be unix-like systems, such as Linux. If you want to see its power, then look at the following code. It’s the popular lottery spanish game “la primitiva”. It gives you six sorted numbers per bet:

Take into account that following the colon “:” text must be indented. I don’t know why I can’t indent text here, so be aware.

###########################################
#!/usr/bin/python

# The popular Spanish play of Primitiva
# This little program gives you 6 results per bet
# It prints the result to the screen

from random import *

results=6
bottom=1
up=49

def repeated(primitiv,pos):
for j in range(pos,0,-1):
if primitiva[pos]==primitiva[j-1]:
return 1
return 0

def work_it_out(primitiva):
for i in range(results):
primitiva[i]=randint(bottom,up)
while repeated(primitiva,i):
primitiva[i]=randint(bottom,up)

primitiva=[0,0,0,0,0,0]
num_bets=int(raw_input(“Introduce the number of bets: “))
for i in range(num_bets):
work_it_out(primitiva)
primitiva.sort()
print i+1,”: “,primitiva
print
raw_input(“tecleja una tecla per acabar”)
##########################################

Advertisements

About jordilin

I'm a Senior Software Engineer with an MSc in Telecommunications Engineering. I've got a range of interests including Linux, a very powerful and limitless operating system, travelling, gastronomy and technology.
This entry was posted in General Blogging. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s