You are on page 1of 3

59. print(('-').

join(headEditor))
L = ["sentence", "contains", "five", "words."] Result:
L.insert(0, "This") editor-in-chief
print(" ".join (L)) 68.
del L[3] carousel = ["merry", "go", "round"]
L.insert(3, "six") print(('-').join(carousel))
L.insert(4, "different") Result:
print(" ".join (L)) Merry-go-round
Result: 69. motto = ["e", "pluribus", "unum"]
This sentence contains five words. print(("**").join(motto))
This sentence contains six different words. Result:
60. e**pluribus**unum
L = ["one", "for", "all"] 70. allDay = "around-the-clock"
L[0], L[-1] = L[-1], L[0] print(allDay.split('-'))
print(L) Result:
Result: ['around', 'the', 'clock']
['all', 'for', 'one']
71. state = "New York,NY,Empire State,Albany"
61. stateFacts = state.split(',')
name = input("Enter name with two parts: ") print(stateFacts)
L = name.split() Result:
print("{0:s}, {1:s}".format(L[1], L[0])) ['New York', 'NY', 'Empire State', 'Albany']
(Assume the name entered is Charles Babbage.)
Result: 72. nations = "France\nEngland\nSpain"
Enter name with two parts: Charles Babbage countries = nations.split()
Babbage, Charles print(countries)
Result:
62. ['France', 'England' , 'Spain']
name = input("Enter name with three parts: ")
L = name.split() 73. nations = "France\nEngland\nSpain\n"
print(L[0], L[2]) countries = nations.split()
Result: print(countries)
Enter name with three parts: Guido van Rossum Result:
Guido Rossum ['France', 'England', 'Spain']
74. # The three lines of Abc.txt contain a b, c, d
infile = open("Abc.txt", 'r')
alpha = [line.rstrip() for line in infile]
63. infile.close()
name = input("Enter name with three parts: ") word = ("").join(alpha)
L = name.split() print(word)
print("Middle Name:", L[1]) Result:
Result: ab,c,d
Enter name with three parts: Guido van Rossum
Middle Name: van
64.
list1 = ['h', 'o', 'n', 'P', 'y', 't']
list2 = list1[3:] + list1[:3]
print(("").join(list2)) 75.
Result:
# The three lines of Dev.txt contain mer, gram, pro
Python
infile = open("Dev.txt", 'r')
65. dev = [line.rstrip() for line in infile]
tuple1 = ("course", "of", "human", "events", infile.close()
"When", "in", "the") dev[0], dev[-1] = dev[-1], dev[0]
tuple2 = tuple1[4:] + tuple1[:4] word = ("").join(dev)
print ((" ".join(tuple2))) print(word)
Result: Result:
When in the course of human events Programmer
66. 76.
list1 = ["is", "Less", "more."] # The two lines of Live.txt contain Live, let
list1[0], list1[1] = list1[1], list1[0] infile = open("Live.txt", 'r')
print (" ".join(list1)) words = [line.rstrip() for line in infile]
Result: infile.close()
Less is more. words.append(words[0].lower())
67. quote = (" ").join(words) + '.'
headEditor = ["editor", "in", "chief"] print(quote)
Result:
Live let live. 84.
77. t = (1, 2, 3)
# The three lines of Star.txt contain your, own, star. t = (0,) + t[1:]
infile = open("Star.txt", 'r') print(t)
words = [line.rstrip() for line in infile] Result:
infile.close() (0,2,3)
words.insert(0, "Follow") 85.
quote = (" ").join(words) list1 = ["soprano", "tenor"]
print(quote) list2 = ["alto", "bass"]
Result: list1.extend(list2)
Follow your own star print(list1)
Result:
['soprano', 'tenor', 'alto', 'bass']
86.
list1 = ["soprano", "tenor"]
list2 = ["alto", "bass"]
print(list1 + list2)
Result:
78. ['soprano', 'tenor', 'alto', 'bass']
nums = (6, 2, 8, 0)
print("Largest Number:", max(nums)) 87.
print("Length:", len(nums)) list1 = ["gold"]
print("Total:", sum(nums)) list2 = ["silver", "bronze"]
print("Number list:", list(nums)) print(list1 + list2)
Result: Result: ['gold', 'silver', 'bronze']
Largest Number: 8 89.
Length: 4 list1 = ["mur"] * 2
Total: 16 print(list1)
Number list: [6, 2, 8, 0] print("".join(list1))
79. Result:
phoneNumber = "9876543219" ['mur', 'mur']
list1 = list(phoneNumber) murmur
list1.insert(3, '-') 91.
list1.insert(7, '-') t = ("Dopey", "Sleepy", "Doc", "Grumpy","Happy",
phoneNumber = "".join(list1) "Sneezy", "Bashful")
print(phoneNumber) print(t[4:20])
Result: Result:
987-654-3219 ('Happy', 'Sneezy', 'Bashful')
80. In Exercises 95 through 100, identify all
word = "diary" errors.
list1 = list(word)
list1.insert(3, list1[1])
95.
del list1[1] threeRs = ["reading", "riting", "rithmetic"]
word = "".join(list1) print(threeRs[3])
print(word) list out of range
Result: 96.
dairy word = "sea"
81. location = numbers.index(7)
nums = (3, 9, 6) word[1] = 'p'
print(list(nums)) print(word)
Result: name 'numbers' is not defined
[3,9,6] 97.
82. list1 = [1, "two", "three", 4]
nums = [-5, 17, 123] print(" ".join(list1))
print(tuple(nums)) sequence item 0: expected str instance, int found
Result: 98. # Four virtues presented by Plato
(-5,17,123) virtues = ("wisdom", "courage", "temperance",
83. "justice")
word = "etch" print(virtues[4])
L = list(word) tuple index out of range
L[1] = "a"
print("".join(L)) 99.
Result:
title = ("The", "Call", "of", "the", "Wild")
each
title[1] = "Calm"
print(" ".join(title))
100.
words = ("Keep", "cool", "but", "don't")
words.append("freeze.")
print(words)
'tuple' object has no attribute 'append'

You might also like