# 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
vrijdag 22 januari 2016
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
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.
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.
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
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])
x = ("What shall we do with the drunken sailor?\n")
print (x[0:4])
print (len(x))
print (x[40])
Abonneren op:
Posts (Atom)
Enlarging Libreoffice window completely with command
You can open the LibreOffice window completely by pressing the CTRL+Shift+J keys together.
-
You can open the LibreOffice window completely by pressing the CTRL+Shift+J keys together.
-
The mount point must be placed in the media folder: /media/porter/mount_point otherwise the file manager won't discover the extra hard ...
-
:s/\v(.*)/- \1/g (very magic) :s/\(.*\)/- \1/g The above commands do the same thing: adding a dash before the line. So, Wha...