Question

1. Write a function called ordinal_sum that accepts a string argument and returns the sum of...

1. Write a function called ordinal_sum that accepts a string argument and returns the sum of the ordinal values of each character in the string. The ordinal value of a character is its numeric Unicode code point in decimal.

2. Write code that creates a Python set containing each unique character in a string named my_string. For example, if the string is 'hello', the set would be {'h', 'e', 'l', 'o'} (in any order). Assign the set to a variable named my_set. Assume that my_string has already been initialized.

3. Write a predicate function called check_list that accepts a list of integers as an argument and returns True if at least half of the values in the list are less than the first number in the list. Return False otherwise.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def ordinal_sum(string):
    total = 0
    for x in string:
        total += ord(x)
    return total
#####################################
my_set = set(my_string)

#####################################

def check_list(lst):
    first = lst[0]
    count = 0
    for x in lst:
        if x<first:
            count += 1
    return count>=(len(lst)/2)

Add a comment
Know the answer?
Add Answer to:
1. Write a function called ordinal_sum that accepts a string argument and returns the sum of...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT