In: Computer Science
EXPLAIN ANS PLEASE:
PYTHON
1. s = 'abc'
print(s[0:] + s[-2:2] + s[:1])
2. def mirrorOnWheels(s):
prev = 0
for current in range(1, len(s) - 1):
prev = current - 1
next = current + 1
if s[prev] == s[next]:
break
else:
continue
return 0
return prev
s = 'Good decision!'
print(mirrorOnWheels(s))
3. mixture = {1:[1, 2, 0], 2:[2, 0, 1], 0:[0, 1, 2]}
print(mixture[2][2])
4. noOddHeroes = []
heroes = ['superman', 'batman', 'aquaman']
for hero in heroes:
if len(hero) % 2 == 0:
noOddHeroes.append(hero)
print(noOddHeroes)
5. candyOnStick = 'lolli lolli lolli lollipop lollipop'
wordList = candyOnStick.split('i')
d = {}
for word in wordList:
if word not in d:
d[word] = 1
else:
d[word] += 1
print(len(d))
6. def oldMcDonald(farm):
result = 0
for animal in farm:
if animal[0] in farm[animal]:
result += 1
return result
farm = {'cow':'moo', 'duck':'quack', 'cricket':'chirp'}
print(oldMcDonald(farm))
7. def analyzer(fileName):
inputFile = open(fileName)
line = inputFile.readline()
inputFile.close()
return line.count(',')
quotes = open('alice.txt', 'w')
quotes.write('Now, here, you see, it takes all the
running\n')
quotes.write('you can do, to keep in the same place.\n')
quotes.close()
print(analyzer('alice.txt'))
Please ask 1 question at a time although i have done 3. for problem 1, problem 3 and problem 4
For problem 2, the indentation is lost, so its hard to read the code