PLEASE HURRY, will upvote if correct
python
Write a method that prints characters using the following header:
def printChars(ch1,ch2):
this function prints out the characters between ch1 and ch2 inclusive. Assumption is that ch2 is always bigger than c1 and both lower cases.
also
Write a function that accepts a list as an argument and prints the number of occurrence of each item
def itemOccurence(myList):
i.e.
input
("Hello",123, 342, 123, "Hello",123)
output:
2 times "Hello"
3 times 123
1 time 342
def printChars(ch1, ch2): ch = ord(ch1) while ch <= ord(ch2): print(chr(ch)) ch += 1 # Testing the function here. ignore/remove the code below if not required printChars('d', 'h') def itemOccurence(myList): already_printed = [] for item in myList: count = 0 for temp in myList: if temp == item: count += 1 if item not in already_printed: already_printed.append(item) if count != 1: print(count, "times", item) else: print(count, "time", item) # Testing the function here. ignore/remove the code below if not required itemOccurence(("Hello", 123, 342, 123, "Hello", 123))
Get Answers For Free
Most questions answered within 1 hours.