Friday, 29 April 2011

python program for reversing the position of the words in a line

This is a program for reversing the position of the words in a line

the code is

f = open('words.txt')
iamlist = []
while True:
    line = f.readline()
    if len(line) == 0 :
        break
    else:
        iamlist = line.rstrip('\n').split(" ")
        iamlist.reverse()
        print " ".join(iamlist)

f.close()

i/p(words.txt):

this is a text string
this is another string

o/p:

[parthi@localhost pyth files]$ python reversewords.py
string text a is this
string another is this


python script(program) for reversing every line in a file

hi,

I was given some exercises in python, today i tried some of them first program i tried was to reverse every line in a file and print them.

I finished the exercise, the program is

f = open('words.txt')
while True:
    line = f.readline().rstrip('\n')
    if len(line) == 0 :
        break
    else:
        print line[::-1]

f.close()

i/p(words.txt):

this is a text string
this is another string

o/p:

gnirts txet a si siht
gnirts rehtona si siht



Wednesday, 27 April 2011

ruby in 15 min

Today my friend went to a site which teaches ruby basics in 15 min with ruby interpreter in your browser

if u have 15 min and interested,

Give it a try :)

the link is....
http://tryruby.org/

fahrenheit to celcius and celcius to fahrenheit program in python

hi,

i am new to the python scripting.

today i tried farenheit to celcius and celcius to fahrenheit to celcius conversion in python.

it was really easy and fun to work with python

the code is:

#! /usr/bin/python

print "enter 'c' to convert fahrenheit to celcius"
print "enter 'f' to convert celcius to fahrenheit"
x = raw_input("c or f:")
if x == 'c':
    fahren = float(raw_input("please enter a value:  "))
    cent = ((fahren-32)*5)/9
    print float(cent)
elif x == 'f':
    cen = float(raw_input("please enter a value:  "))
    fahrenh = ((cen*9)/5)+32
    print float(fahrenh)
else:
    print "invalid input :( sorry try again"

i have also added some screen shots for reference :)

Tuesday, 26 April 2011

Installing vlc in fedora 14

hai,

I am new to the linux environment. I 've installed VLC player in fedora 14 today.

the command i used to install vlc are.

$ su -
$ rpm -ivh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm
$ yum install vlc

thats it vlc will be installed :)

* the su command is to login as super user, who has the privilege to install software packages...

*the second rpm(redhat package manager) command helps to find the package in rpm derivative.

*yum install command helps to install the software

this is what i have learnt today :)