print "The character \\0 is used to terminate a string."
str1 = "To be or not to be"
str2 = ",that is a question"
print "Length of the string \"", str1, "\" is ", len(str1), " characters"
print "Length of the string \"", str2, "\" is ", len(str2), " characters"
str1 = "Computers do what you tell them to do, not what you want them to do."
str2 = "When you put something in memory, remember where you put it."
str3 = "Never test for a condition you don't know what to do with."
print "There are 3 strings."
print "The string: "
print str1
print "contains ", len(str1), " characters"
print "The string: "
print str2
print "contains ", len(str3), " characters"
print "The string: "
print str3
print "contains ", len(str3), " characters"
preamble = "The joke is: "
str1 = "My dog hasn\'t got any nose.\n"
str2 = "How does your dog smell then?\n"
str3 = "My dog smells horrible.\n"
joke = str1 + str2 + str3
print preamble
print joke
print "Type in the first word (maximum 20 characters): ",
word1 = raw_input()
print "Type in the second word (maximum 20 characters): ",
word2 = raw_input()
if(word1 == word2):
print "You have entered identical words"
else:
print "%s precedes %s\n" %((word2 if(word1 > word2) else word1), (word1 if(word1 > word2) else word2))
str1 = "This string contains the holy grail."
str2 = "the holy grail"
str3 = "the holy grill"
if str2 in str1:
print "\"%s\" was found in \"%s\"\n" %(str2, str1)
else:
print "\n\"%s\" was not found." %str2
if not(str3 in str1):
print "\"%s\" was not found.\n" % str3
else:
print "\nWe shouldn't get to here!"
print "Enter some prose that is less than 1000 characters (go on typing hit enter to terminate):"
str1 = raw_input()
if len(str1) > 1000:
print "Maximum permitted input length exceeded."
list_str1 = str1.split(" ")
print "The words in the prose that you entered are: "
for i in range(0, len(list_str1)):
print list_str1[i], "\t",
if i % 5 == 0:
print "\n"
print "Words found ", len(list_str1)
nLetters = 0
nDigits = 0
nPunct = 0
print "Enter an interesting string of less than 100 characters: "
str1 = raw_input()
for char in str1:
if char.isalpha():
nLetters += 1
elif char.isdigit():
nDigits += 1
elif char == " ":
pass
else:
nPunct += 1
print "Your string contained %d letters, %d digits and %d punctuation characters. " %(nLetters, nDigits, nPunct)
print "Enter the string to be searched (less than 100 characters): ",
text = raw_input()
print "Enter the string sought (less than 40 characters):",
substring = raw_input()
print "First string entered: ", text
print "Second string entered: ", substring
text = text.upper()
substring = substring.upper()
print "The second string %s found in the first. " %("was not" if not substring in text else "was")
import numpy
print "Enter text (hit enter to exit): ",
text = raw_input()
text_split = text.split()
distinct_words = []
for i in text_split:
if i not in distinct_words:
distinct_words.append(i)
word_count = numpy.zeros(len(distinct_words))
for i in range(len(distinct_words)):
for j in range(len(text_split)):
if distinct_words[i] == text_split[j]:
word_count[i] += 1
for i in range(len(distinct_words)):
print distinct_words[i], int(word_count[i])
if i == 5:
print ""