In the book All Creatures of Mythology , gnomes are kind, bearded creatures, whi
ID: 3759378 • Letter: I
Question
In the book All Creatures of Mythology, gnomes are kind, bearded creatures, while goblins tend to be bossy and simple-minded. The goblins like to harass the gnomes by making them line up in groups of three, ordered by the length of their beards. The gnomes, being of different physical heights, vary their arrangements to confuse the goblins. Therefore, the goblins must actually measure the beards in centimeters to see if everyone is lined up in order.
Your task is to write a function to assist the goblins in determining whether or not the gnomes are lined up properly, either from shortest to longest beard or from longest to shortest. The input will come from the file gnome.txt which starts with a line containing a single integer N, 0 <N < 30, which is the number of groups to process. Following this are N lines, each containing three distinct positive integers less than 100. For each group, a line saying "Ordered" or "Unordered" should be printed:
Usage:
>>> gnome()
Ordered
Unordered
Ordered
Explanation / Answer
Answer :
f = open('gnome.txt').readlines()[1:]
def checkfunction(w):
if sorted(w) == w:
return True
for v in f:
v=v.split()
if checkfunction(v) == True:
print " ".join(v),"Ordered"
else:print " ".join(v),"Unordered"
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.