1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
tino4ka555 [31]
3 years ago
6

Write a programmer defined function that compares the ASCII sum of two strings. To compute the ASCII sum, you need to compute th

e ASCII value of each character of the string and sum them up. You will thus need to calculate two sums, one for each string. Then, return true if the first string has a larger ASCII sum compared to the second string, otherwise return false. In your main function, prompt the user to enter two strings with a suitable message and provide the strings to the function during function call. The user may enter multiple words for either string. Then, use the Boolean data returned by the function to inform which string has the higher ASCII sum.
Computers and Technology
1 answer:
MariettaO [177]3 years ago
3 0

Answer:

The program in Python is as follows:

def ASCIIsum(str1,str2):

   asciisum1 = 0;    asciisum2 = 0

   for chr in str1:

       asciisum1 += (ord(chr) - 96)

   for chr in str2:

       asciisum2 += (ord(chr) - 96)

   if asciisum1 > asciisum2:

       return True

   else:

       return False

str1 = input("Enter first string: ")

str2 = input("Enter second string: ")

if ASCIIsum(str1,str2) == True:

   print(str1,"has a higher ASCII value")

else:

   print(str2,"has a higher ASCII value")

Explanation:

This defines the function

def ASCIIsum(str1,str2):

This initializes the ascii sum of both strings to 0

   asciisum1 = 0;    asciisum2 = 0

This iterates through the characters of str1 and add up the ascii values of each character

<em>    for chr in str1:</em>

<em>        asciisum1 += (ord(chr) - 96)</em>

This iterates through the characters of str2 and add up the ascii values of each character

<em>    for chr in str2:</em>

<em>        asciisum2 += (ord(chr) - 96)</em>

This returns true if the first string has a greater ascii value

<em>    if asciisum1 > asciisum2:</em>

<em>        return True</em>

This returns false if the second string has a greater ascii value

<em>    else:</em>

<em>        return False</em>

The main begins here

This gets input for first string

str1 = input("Enter first string: ")

This gets input for second string

str2 = input("Enter second string: ")

If the returned value is True

if ASCIIsum(str1,str2) == True:

Then str1 has a greater ascii value

   print(str1,"has a higher ASCII value")

If otherwise

else:

Then str2 has a greater ascii value

   print(str2,"has a higher ASCII value")

You might be interested in
Now that you have explored some of the possibilities for using Excel at home, what concerns or questions do you have about using
lora16 [44]

This seems like an opinionated question, I suggest attempting to answer it yourself.

8 0
3 years ago
You can insert pictures,such as scanned photographs, line art, and artwork, into a presentation. (points : 2) true false
Lady bird [3.3K]
True, i have done this before in my presentation slides
5 0
3 years ago
Mary needs to choose the menu in order to place the text in a desired fashion around the image.
mixas84 [53]
Full features



Option C


hope this one help
6 0
3 years ago
For the following scenario, indicate whether the action is a good practice or bad practice for safeguarding your personally iden
a_sh-v [17]

Answer: it is good practice

Explanation: Even if you are able to guess the phrase that Sierra uses, you will find it very difficult to write them exactly as she does hence you cannot have access to her bank account

8 0
3 years ago
BRAINLEST TO THE CORRECT ANSWER!!!!!
lisabon 2012 [21]

Answer:

puede ser la cok puede ser la c

8 0
3 years ago
Read 2 more answers
Other questions:
  • *FREE POINTS* If you comment and follow me this will give up lot of points :p seriously I will follow u back if u do it :p​
    11·2 answers
  • Spreadsheet software creates a ____, composed of a grid of columns and rows
    5·1 answer
  • What is an activity that can help you enhance the appearance of your computer’s desktop?
    12·2 answers
  • A customer has a web server for a small business. The business uses both wired and wireless networking. A Linksys WRT300N wirele
    13·1 answer
  • What error occurs when you perform an illegal math operation such as divide by zero
    13·1 answer
  • Mobile phones that function as credit cards are called _____.
    11·1 answer
  • Which routing protocol does an exterior router use to collect data to build its routing tables?
    8·1 answer
  • When targeting customers of the consumer population at market a product, what type of segmentation information would be most hel
    12·2 answers
  • What is the term used to describe the basic unit of data passed from one computer to another
    14·1 answer
  • Data type can only be true or false <br><br> Answer: Bool
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!