aList = [1, 'Mercy', 20, 'Cyber', 300].
a) Write a single line of Python statement to print the value 20 from aList.
b) Write a single line of Python statement to print the character b from aList.
c) Write a single line of Python statement to print erc from aList.
d) Write a Python segment that print a sequence number starting from 1 followed by ")" and an element for each element of the list. Use a for loop and format function. So it should display
1) 1
2) Mercy
3) 20
4) 300
5) bbdcc
e) Write a Python function that counts a character from a list. The function countChar() takes a character and a list. A list contains numbers and text as illustrated above. Please fill in the blank below:
char = 'c'
aList = [1, 'Mercy', 20, 300, 'bbdcc']
def countCha(char,list):
i=0
for e in list:
if str(e).isdigit():
_____________
else:
for ______ in e:
if ea == char:
_____________
return i
print("{} has {} times of {}".format(aList, ________________, char))
In this case, the outcome of the print statement will be
[1, 'Mercy', 20, 300, 'bbdcc'] has 3 times of c
aList = [1, 'Mercy', 20, 'Cyber', 300]
# a) Write a single line of Python statement to print the value 20 from aList.
print(aList[2])
# b) Write a single line of Python statement to print the character b from aList.
print(aList[3][2])
# c) Write a single line of Python statement to print erc from aList.
print(aList[1][1:4])
# d) Write a Python segment that print a sequence number starting from 1 followed by ")" and an element for each element of the list. Use a for loop and format function. So it should display
for i in range(0,len(aList)):
print(str(i+1)+")",aList[i])

# e) Write a Python function that counts a character from a list. The function countChar() takes a character and a list. A list contains numbers and text as illustrated above. Please fill in the blank below:
char = 'c'
aList = [1, 'Mercy', 20, 300, 'bbdcc']
def countCha(char,list):
i=0
for e in list:
if str(e).isdigit():
i = i # do nothing there is no 'c' when e is digit
else:
for ea in e:
if ea == char:
i += 1
return i

print("{} has {} times of {}".format(aList, countCha(char,aList), char))
aList = [1, 'Mercy', 20, 'Cyber', 300]. a) Write a single line of Python statement to...
Write a Python function called more() that takes three string inputs and outputs a string Formally, the function signature and output are given by rucharist, char: str words str) > str Use the same names for the input arguments as shown above Note that charl and char2 will always be a string of length 1 (ie, it is a single character. The function checks which of charl or char2 appears more often in the word string and returns that character...
Consider the list myList: myList = ["a", "America", "1", [5,3,9], "3", ["Mercy"]] #1 1) The Python statement __________________ returns a #2 2) The Python statement __________________ returns America #3 3) The Python statement __________________ returns Ame #4 The type of the third element is _______. #6 The Python statement __________________ returns the following: ['Mercy'] #7 The python statement temp = _______ converts the third element to integer and assigns the result to temp. #8 Consider the fourth element of myList...
In python
Write a function named printList to print the elements of a list with labels showing each element's order in the list. The function header should like this: def printList(aList): And here is an example run: > > > myList = [92.5, 127.1, 9, 104.2, 78.4] > > > printList(myList) 0 92.5 1 127.1 2 9 3 104.2 4 78.4 Test your function from the Python shell window on various types of lists with varying lengths.
Python Programming Given scList that contains numeric scores, write a SINGLE Python statement to remove the list's last element from the list AND store that value into a variable called score.
*Java* Hi. I need some help with creating generic methods in Java. Write a program GenMethods that has the following generic methods: (1) Write the following method that returns a new ArrayList. The new list contains the nonduplicate (i.e., distinct) elements from the original list. public static ArrayList removeDuplicates(ArrayList list) (2) Write the following method that shuffles an ArrayList. It should do this specifically by swapping two indexes determined by the use of the random class (use Random rand =...
IN PYTHON ''' Helper func 3: checksum_ISBN Input: a list with 9 single digit number in it (first 9 digit in ISBN) Output: print out: "The correct checksum digit is:__. Now we have a legit ISBN: _____" Hint: just loop through 0-9, test every one with helper func1 to find out the one checksum that forms a legit ISBN with the correct ISBN in lis (10 numbers), call helper func2 to format it correctly. Then print the final result. '''...
in
python and according to this
#Creating class for stack
class My_Stack:
def __init__(self):
self.items = []
def isEmpty(self):
return self.items == []
def Push(self, d):
self.items.append(d)
def Pop(self):
return self.items.pop()
def Display(self):
for i in reversed(self.items):
print(i,end="")
print()
s = My_Stack()
#taking input from user
str = input('Enter your string for palindrome checking:
')
n= len(str)
#Pushing half of the string into stack
for i in range(int(n/2)):
s.Push(str[i])
print("S",end="")
s.Display()
s.Display()
#for the next half checking the upcoming string...
python format: write a program that displays, 10 numbers per line, all the numbers from 100 to 200 that are divisible by 5 or 6, but not both. The numbers are separated by exactly one space My Code: count = 0 for i in range (100, 201): if (i %6==0 and i %5!=0) or (i%5==0 and i%6!=0): print(str(i), "") count = count + 1 if count == 10: string = str(i) + str("") print(string)...
Write a single Python statement that calls silly2 and results in the output: 2 2 We're dead, Fred def silly2(nums, indices, extra=None): print(len(nums), len(indices)) new_indices = [] for i in indices: if i >= 0 and i < len(nums): new_indices.append(i) if extra: new_indices.append(extra) try: for index in new_indices: if index < len(nums): print(nums[index]) except IndexError: print("We're dead, Fred") silly2([1, 2], [0, -1])
Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a function named smaller that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display all numbers in the list that are smaller than the number n. Write a code that declares and initializes a list of numbers and a variable number and pass them to the function to test it. Please see the outcome below:...