M.S. 53 Light Poster

for example I don't know what this is called » [('cat', 'meow'), ('dog', 'ruff')]

It's called a list of tuples

so I can now remove the square brackets but I want to make it liek this ↴

catmeow
dogrugg

You can do something like this:

your_list = [('cat', 'meow'), ('dog', 'ruff')]
for tpl in your_list:
    print tpl[0]+tpl[1]
M.S. 53 Light Poster
def main():
    with open(raw_input("Enter file name: ", "r")) as fin:
        for num, line in enumerate(fin.readlines()):
            print("%d: %s"%(num+1, line))

it is without error checking, u
you can add exception catching to it.

M.S. 53 Light Poster

I'm using py4a on android and it helps me script things for my android phone.
stuff like searching messages for desired words,
text encryption and sending via sms
reboot options for root devises
bluetooth control with gui
and some more, I scripted already.

M.S. 53 Light Poster

One step further:

data = ''' Max Medium 12345678 58 152
Jane Johnson 87654321 78 201
Bill Bupkiss 23456789 29 29
Nate Newby 98765432 0 0
Harold Humphries 11223344 43 160
Carol Cramer 22334455 102 400
Alvin Adams 33445566 67 120
Fred Frederick 44556677 81 250
Phillip Parker 55667788 44 168
Sam Spade 24681357 16 30 '''

import pprint

data_list = [[int(item) if len(item)<=3 and item.isdigit() else item for item in line.split()] for line in data.split('\n')]

pprint.pprint(data_list)
M.S. 53 Light Poster

you have to assign thevariable before using it. in your case, replace the line 1 and 2 with each other.

in python 2.x use raw_input instead of input and then convert it to integer or float.

M.S. 53 Light Poster

Importing modules inside anonymous functions:

t = lambda: __import__('time').localtime()
print('Date: %s/%s/%s'%(t().tm_mday, t().tm_mon, t().tm_year))
M.S. 53 Light Poster

or

def shippingRate ( poundage , classification ):
    shipping_rate = poundage * classification
    return shipping_rate
M.S. 53 Light Poster

you should return shipping_rate in the second function:

def shippingRate ( poundage , classification ):
    return poundage * classification
M.S. 53 Light Poster

if you mean to write and run code, there is no support for python 3.3. SL4A only supports 2.6.2 and 3.0.1.

M.S. 53 Light Poster

Thanks for this informing comment, Gribouillis.
I corrected iter and added one more function.
any further guide is appreciated.

#from math import*

class Triangle(object):
    """Checks if given sides can make a Triangle then shows the Angles."""
    def __init__(self, a, b, c):
        self.a = a
        self.b = b
        self.c = c
        self.triangletype = ""
        self.A = self.B = self.C = 0
        self.__check_triangle()

    def __check_triangle(self):
        """Checks if given sides can make a Triangle"""
        if not (abs(self.c-self.b) < self.a < self.c+self.b):
            raise ValueError("Not a Triangle!")

    def get_angles(self):
        """Calculates the Angles based on the Cosine Rule."""
        self.A = degrees(acos((self.b**2+self.c**2-self.a**2)/float(2*self.b*self.c)))
        self.B = degrees(acos((self.a**2+self.c**2-self.b**2)/float(2*self.a*self.c)))
        self.C = 180 - (self.A+self.B)
        return self.A, self.B, self.C

    def triangle_type(self):
        """Gets the type of Triangle."""
        if self.A == 90 or self.B == 90 or self.C == 90:
            self.triangletype = "Right"
        elif self.a == self.b == self.c:
            self.triangletype = "Equilateral"
        elif (self.A == self.B or self.A == self.C or self.C == self.B):
            self.triangletype = "Isosceles"
        else:
            self.triangletype = "Scalene"

        return self.triangletype



if __name__ == '__main__':
    a,b,c =  (float(x) for x in raw_input("Enter Sides(Separated by a Space): ").split())
    t = Triangle(a,b,c)
    print "A: %.2f\nB: %.2f\nC: %.2f"%t.get_angles()
    print t.triangle_type()
M.S. 53 Light Poster

Thank you pyTony. your Code motivated me to read about itertools :)

Using takewhile doesnt return any word, but an empty list. I think its bacause when takewhile meets the first matching word, it stops iteration and excludes the first found word from the list. In other word, the list of longest words will always be Empty.

PS: yes I call myself beginner because I have no background inProgramming, CS or any other kind of tech. I am a Rehabilitation profesional. BUT I'm in Love with Python and whenever I find free time, I spend it on Learning python. :D

M.S. 53 Light Poster

a ')' at the end of line 1 is missing:

celsius = float(input("What is the Celsius temperature? "))
vegaseat commented: sharp eye +14
M.S. 53 Light Poster

All the Info you need, is accessible through the API documentation: menu > help > API help > bluetooth facade.

from android import Android

droid = Android()

check = droid.checkBluetoothState().result
if check != 1:
    droid.toggleBluetoothState(1,0)
    print "Bluetooth turned ON!"
    droid.bluetoothMakeDiscoverable(300)
    print "Bluetooth is Discoverable for 300sec now"

else:
    droid.toggleBluetoothState(0,0)
    print "Bluetooth turned OFF!"
M.S. 53 Light Poster
ordertype =  raw_input(" Is the order for pickup or delivery? ")

while True:
    if not (ordertype.lower() in ["p","d"]):
        print "No, Enter only P or D!"
        ordertype =  raw_input("Is the order for pickup or delivery? ")
    else:
        print "Ok, %s Entered" %ordertype
        break
dan.nitschke commented: Excellent Response! +0
M.S. 53 Light Poster

sorry for the typo. please correct line 5 like this:

if query == "y":
M.S. 53 Light Poster

no need to open and close the file several times. for names printing in different lins you can strip the end of line symbol. a simple function is what I would use:

import random

def name_gen()
    query = raw_input("Whould you like to generate a random name? y/n")
    if query == "y" 
        a = random.randint(1, 10)
        b = random.randint(1, 10)
        first_name = open ( 'fname.txt' ).readline(a).strip("\n") 
        last_name = open ( 'lname.txt' ).readline(b).strip("\n")
        print(first_name, last_name)
        name_gen()

name_gen()

there are more solutions that far more expert people here can provide. so condider this post as one option from a novice that I am.
btw, I have not tested this and just posted it as it came to my mind :D

M.S. 53 Light Poster

How the following code can be rewritten in a better way?

 #!/usr/bin/env python

"""Simple program for finding popular names
over last 100 years, in response to vegaseat's
last post in Projects for Beginners(9/1/2012).

It first lists the popular names and then search
for entered name by user"""

oldnames = """Mary,Helen,Margaret,Anna,Ruth
Elizabeth,Dorothy,Marie,Florence,Mildred
Alice,Ethel,Lillian,Gladys,Edna
Frances,Rose,Annie,Grace,Bertha
Emma,Bessie,Clara,Hazel,Irene
Gertrude,Louise,Catherine,Martha,Mabel
Pearl,Edith,Esther,Minnie,Myrtle
Ida,Josephine,Evelyn,Elsie,Eva
Thelma,Ruby,Agnes,Sarah,Viola
Nellie,Beatrice,Julia,Laura,Lillie
Lucille,Ella,Virginia,Mattie,Pauline
Carrie,Alma,Jessie,Mae,Lena
Willie,Katherine,Blanche,Hattie,Marion
Lucy,Stella,Mamie,Vera,Cora
Fannie,Eleanor,Bernice,Jennie,Ann
Leona,Beulah,Lula,Rosa,Ada
Ellen,Kathryn,Maggie,Doris,Dora
Betty,Marguerite,Violet,Lois,Daisy
Anne,Sadie,Susie,Nora,Georgia
Maude,Marjorie,Opal,Hilda,Velma"""

newnames = """Emily,Madison,Emma,Hannah,Abigail
Olivia,Ashley,Samantha,Alexis,Sarah
Elizabeth,Isabella,Alyssa,Grace,Lauren
Taylor,Jessica,Brianna,Kayla,Sophia
Anna,Natalie,Victoria,Chloe,Sydney
Jasmine,Hailey,Megan,Rachel,Morgan
Julia,Destiny,Ava,Jennifer,Kaitlyn
Mia,Katherine,Alexandra,Haley,Savannah
Nicole,Maria,Allison,Mackenzie,Stephanie
Brooke,Amanda,Ella,Makayla,Faith
Kaylee,Jenna,Andrea,Katelyn,Mary
Jordan,Gabrielle,Rebecca,Paige,Madeline
Kimberly,Trinity,Zoe,Michelle,Sara
Lily,Kylie,Alexa,Caroline,Vanessa
Amber,Angelina,Gabriella,Lillian,Riley
Sierra,Danielle,Leah,Jada,Autumn
Erin,Maya,Ariana,Audrey,Isabel
Sofia,Marissa,Bailey,Jacqueline,Melissa
Claire,Evelyn,Shelby,Jocelyn,Mariah
Avery,Leslie,Melanie,Arianna,Aaliyah"""



old_names = [name.lower() for name in (oldnames.replace("\n", ",").split(","))]

new_names = [name.lower() for name in (newnames.replace("\n", ",").split(","))]


def find_name():
    print "Popullar names in last 100 years:"
    for name in new_names:
        if name in old_names:
            print name
    print "*"*50

    name = raw_input("Enter a name:").lower()

    if (name in old_names) and (name in new_names):
        print name, "is still a popullar name over 100 years"
    elif (name in old_names) and not (name in new_names):
        print name, "is an old name"
    elif (name in new_names) and not (name in old_names):
        print name, "is a new name"
    else:
        print name, "is not in the lists"

find_name()
Lardmeister commented: nice approach +10
TrustyTony commented: Interesting of '\n' -> ',' and split approach +12
M.S. 53 Light Poster

if you want it to work with every site,I guess you need to consider the encoding too:

print sourcecode.decode("utf8")
M.S. 53 Light Poster
from os import path

PATH = "folder_path/file.txt"
if path.exists(PATH) and path.isfile(PATH):
    print "File does exist"
else:
      print "File doesn't exist!"
Gribouillis commented: best method +13
M.S. 53 Light Poster

My Beginners' Solution:

def main():
    print "This program calculates a numeric value for a name.\n"
    first, last = raw_input("Enter your first and last name (with a space): ").lower().split()
    print "\n","-"*10
    totalFirst = 0
    totalLast = 0
    for ch in first:
        totalFirst += ord(ch)-96
        print ch,"=",ord(ch)-96

    for ch in last:
        totalLast += ord(ch)-96
        print ch,"=",ord(ch)-96

    print "-"*10,"\n",first,"=",totalFirst
    print "-"*10,"\n",last,"=",totalLast
    print "-"*10,"\n",first,last, "=",totalFirst+totalLast

main ()
M.S. 53 Light Poster

for the other part of your question:

word = raw_input('word: ')
word.split()
print '*'.join(word)+'*'

#>>> H*E*L*L*O*
M.S. 53 Light Poster

Yesss! thats it:D
my problem solved with pyTony's Set class.
Thanks so much

M.S. 53 Light Poster

maybe something like this:

porttype = "Gi"
print "sh int counters errors | i %s.*/1 " % porttype

>>> sh int counters errors | i Gi.*/1
JoshuaBurleson commented: You were correct. +4
M.S. 53 Light Poster

Really Thank you Gribouillis for your fast reply.

Yes! zip is what I was in need of Exactly.

I came up with this:

list1=['Item1', 'Item2', 'Item3', 'Item4']
list2=['1','2','3','4']

for i,j in zip(list1, list2):
    print '%s______%s'%(j, i)

and the Result:

1______Item1
2______Item2
3______Item3
4______Item4

Just Curious, Can it be done in another way?