Question

In: Computer Science

EXPLAIN ANS PLEASE: PYTHON 1. s = 'abc' print(s[0:] + s[-2:2] + s[:1]) 2. def mirrorOnWheels(s):...

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'))

Solutions

Expert Solution

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


Related Solutions

def annoying_valley(n): if n == 0: print() elif n == 1: print("*") elif n == 2:...
def annoying_valley(n): if n == 0: print() elif n == 1: print("*") elif n == 2: print("./") print("*") print(".\\") elif n == 3: print("../") print("./") print("*") print(".\\") print("..\\") elif n == 4: print(".../") annoying_valley(3) print("...\\") elif n == 5: print("..../") annoying_valley(4) print("....\\") elif n == 6: print("...../") annoying_valley(5) print(".....\\") else: print("." * (n - 1) + "/") annoying_valley(n - 1) print("." * (n - 1) + "\\") def annoying_int_sequence(n): if n == 0: return [] elif n == 1: return...
Using Python def specialAverage():    Print the number of 0s and then return the average of...
Using Python def specialAverage():    Print the number of 0s and then return the average of either the positive values in the list (if the optional parameter has value 1) or the negative values in the list (if the optional parameter has value 0).    Arguments: a list of numbers : the list can contain any numeric values an integer : this integer is an optional parameter and only takes value 0 or 1, and defaults to 1 if the...
Qno.1 Part(A). IN jAVA if 1.Int abc; 2. Int def = 8; 3. abc = def;...
Qno.1 Part(A). IN jAVA if 1.Int abc; 2. Int def = 8; 3. abc = def; ➢ Describe the procedure how much memory will be allocated when these three lines of codes will execute. ➢ Describe what will happened after execution of each of these line of code in term of memory allocation and data storage Qno.1 Part(B) A capacitor is constructed from two conductive metal plates 30cm x 50cm which are spaced 6mm apart from each other, and uses...
Python #For question 1 and 2 you may not use ''' ''' Question 1 Print the...
Python #For question 1 and 2 you may not use ''' ''' Question 1 Print the messages below without using variables. Output must be 2 lines identical to below: What is the snake's favorite language? "I love Python", said the snake. Question 2 Write a python statements to match the 5 lines of output below. Use a single print statement to produce the list of 4 languages The 3 most popular programming languages of 2020 are: 1.         Python 2.         Javascript 3.         Java 4.         C#...
def myLength(mylist):    count = 0    for index in range(len(myList)):        print(myList[index])       ...
def myLength(mylist):    count = 0    for index in range(len(myList)):        print(myList[index])        count = count + 1    return count def myLength2(mylist):    count = 0    for element in myList:        print(element)        count = count + 1    return count       Use these two functions as examples to write your Python function below! Function 1: Write a function called myCount that takes in two parameters (a list and an item) like...
import sys var = 1 print(var) def function1(myVar):     print(myVar)     var = myVar + 1...
import sys var = 1 print(var) def function1(myVar):     print(myVar)     var = myVar + 1     print(var)     function2(var) def function2(myVar):     print(myVar)     var = myVar + 1     print(var)     function3(var) def function3(myVar):     print(myVar)     var = myVar + 1     print(var) def main(argv):     var = 10     print(var)     function1(var) if __name__=="__main__":     main(sys.argv) 1. As the program runs, what is the first line that will be interpreted by Python, and what action will...
def check(s): #Conditions applied 1,5,6 if len(s)=9 and s[0].isupper() and s[-1].isdigit(): upper_count = sum(1 for c...
def check(s): #Conditions applied 1,5,6 if len(s)=9 and s[0].isupper() and s[-1].isdigit(): upper_count = sum(1 for c in s if c.isupper()) lower_count = sum(1 for c in s if c.islower()) number_count = sum(1 for c in s if c.isdigit()) #Conditions 2,3,4 if upper_count=3 and lower_count==3 and number_count==3: #Condition 7 { Two consecutive alphabets can’t be small } for i in range(1,len(s)): if s[i-1].islower() and s[i].islower() : return 'reject' else: return 'reject' #All conditions satisfies here, so accept return 'accept' else: return...
def annoying_factorial(n): if n == 0 or n == 1: return 1 if n == 2:...
def annoying_factorial(n): if n == 0 or n == 1: return 1 if n == 2: return 2 if n == 3: return 6 if n == 4: return 4 * annoying_factorial(3) if n == 5: return 5 * annoying_factorial(4) if n == 6: return 6 * annoying_factorial(5) else: return n * annoying_factorial(n-1) def annoying_fibonacci(n): if n==0: return 0 if n==1: return 1 if n==2: return 1 if n==3: return 2 if n==4: return annoying_fibonacci(4-1)+annoying_fibonacci(4-2) if n==5: return annoying_fibonacci(5-1)+annoying_fibonacci(5-2) if...
Please answer using python 3 and def functions! Lab 2 Drill 3: (function practice) create and...
Please answer using python 3 and def functions! Lab 2 Drill 3: (function practice) create and use a function named highest() that takes three inputs and returns the highest number. After you have got it working, try calling the function with inputs ‘hat’, ‘cat’, ‘rat’.
Write a program in Python that will print first 100 numbers of the following series: 0,...
Write a program in Python that will print first 100 numbers of the following series: 0, 1, 1, 2, 3, 5, 8……..
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT