vrijdag 22 januari 2016

Counting the number of characters in a string

# Counting the total number of the letter "a" in a string.
 
x = ("What shall we do with the drunken sailor?")

i = "a"
print (x.count(i, 0, 40))

Result:
3

Print a line in reversal

# print the text in reversal.
import sys
x = ("What shall we do with the drunken sailor?")

y = (len(x)-1)
print (y)

while y > 0:
    y = y - 1
    sys.stdout.write(x[y])
print("\n")

Result:
40
rolias neknurd eht htiw od ew llahs tahW

Perl script: What shall we do with the drunken sailor?

#!/usr/bin/perl
use strict;
use warnings;

my $x = "What shall we do with the drunken sailor?\n";
my $y = "Early in the morning.\n\n";
print "$x" x 3;
print "$y";

my $z = "Heave ho, and up she rises\n";
print $z x 3;
print $y;

Result: 
What shall we do with the drunken sailor.
What shall we do with the drunken sailor.
What shall we do with the drunken sailor.
Early in the morning.

Heave ho, and up she rises.
Heave ho, and up she rises.
Heave ho, and up she rises.
Early in the morning.

Online editors van Codingground

The online editors van Codingground:

http://www.tutorialspoint.com/codingground.htm

Making an error in the text

# Hello World program in Python
 
x ="What shall we do with the drunken sailor?"
print (len(x))
print (x[0:5] +"hs"+ x[7:40])

Result: What hsall we do with the drunken sailor

Editing text with python

# editing text with python
 
x = ("What shall we do with the drunken sailor?\n")

print (x[0:4])
print (len(x))
print (x[40])

Enlarging Libreoffice window completely with command

 You can open the LibreOffice window completely by pressing the CTRL+Shift+J keys together.