Question

PLEASE HURRY, will upvote if correct python Write a method that prints characters using the following...

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

Homework Answers

Answer #1
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))
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions