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
Which of the following statements is false ^^^^^Please Help^^^^^^
Dvinal [7]
3, I think. I hope that is right!
3 0
3 years ago
Without a/an ________. a computer is useless
Len [333]
Without a/an Operating system. a computer is useless
3 0
3 years ago
Application of optical fibre​
densk [106]

Answer:

Internet data transfer.

Explanation:

Optical fibre can be used to move information from one place to another. It is used in internet communications, cable television broadcasting, and telephone communication. One common application is for the transfer of data over the internet. Chances are your browser was able to download this web page by receiving data that came from Brainly's servers, and from my computer, through a fibre optic cable.

4 0
3 years ago
7.3 Code Practice edhesive
ASHA 777 [7]

def print_sum(a,b,c):

   print(a+b+c)

one = int(input("Enter the 1st number: "))

two = int(input("Enter the 2nd number: "))

three = int(input("Enter the 3rd number: "))

print_sum(one,two,three)

I wrote my code in python 3.8. I hope this helps.

8 0
3 years ago
For what purpose does a programmer use flowcharts and pseudocode?
Misha Larkins [42]
When there’s a quizlet theirs a way. So the answer is C. Pls give brainliest.
5 0
3 years ago
Read 2 more answers
Other questions:
  • A machine called a centrifuge is used in _____.
    8·1 answer
  • While working on a group project, you notice something does not look right in the presentation. You call a meeting with your tea
    14·2 answers
  • To get started with stock trading and to learn, many people start with this method to learn the ropes and practice with fake mon
    13·1 answer
  • When creating a new user in linux, after entering the name, the username box:?
    9·1 answer
  • Which of the following is not one of the Fatal Four events that cause three out of five construction worker deaths? A. Caught in
    8·2 answers
  • Cookies Are Us runs a series of 100 cookie stores across the Midwestern United States and central Canada. At the end of each day
    13·1 answer
  • Give five examples of physical networking.
    15·1 answer
  • Jennifer has written a short story for children. What should be her last step before she submits the story for publication?
    6·1 answer
  • A user logs in to a virtual world and creates an animated character representing themselves, which they then use to move through
    15·2 answers
  • A web site that contains large numbers of misspelled words and grammatical errors fails which of these general criteria?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!