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
Find the solution of the equation<br>4x+10/3=25?3-x ​
fgiga [73]
I’m going to assume the ? is dividing and if that’s the case X = 1
8 0
3 years ago
Networking Gadgets, Inc. currently employs 8 people but plans to hire 10 more in the next four months. Users will work on multip
kirza4 [7]

Answer:

Following is given the solution to the question.

I hope it will make the idea clear.

Explanation:

7 0
3 years ago
Simplify to obtain a sum of products: (A+B)(C+B)(D?+B)(ACD?+E)
lilavasa [31]

Answer:

(ACD'+BE)

Explanation:

(A+B)(C+B)(D'+B)(ACD'+E)

Product of (A+B)(C+B)

(A+B)(C+B)=AC+AB+BC+B^2 = AC+B(A+C+B)=AC+B

Product of (D'+B)(ACD'+E) with AC+B

(AC+B)(D'+B)(ACD'+E)

(AC+B)(D'+B)=ACD' + ACB +BD +B = ACD'+B(AC+D+1)=ACD'+B

Then we get:

(ACD'+B)(ACD'+E) = ACD'+ACD'E+ACD'B+BE

ACD'(1+E+B)+BE =ACD'+BE

7 0
3 years ago
Use the drop-down menus to explain how to save a presentation to a CD.
Natalka [10]

Answer:

File, Export, name, and Copy to Folder

Explanation:

8 0
3 years ago
Read 2 more answers
Which of the following processes is not part of the rock cycle?
Leviafan [203]
Igneous rock forced below the Earth's surface where it is turned into sedimentary rock through intense heat and pressure.

This process creates metamorphic rocks, not sedimentary.
3 0
3 years ago
Other questions:
  • What does using indirect quotations allow a writer to do?
    7·2 answers
  • _______ are unprocessed facts that a computer feeds on.
    5·1 answer
  • 1. Write a function that will ask the user to enter a value in dollars. The function should calculate and display the equivalent
    9·1 answer
  • Which of these statements makes the most sense? a folder is contained within a file. a file is contained within a folder. a driv
    9·2 answers
  • A relational database is different from a simple database because it has more than one _____.
    13·1 answer
  • You just bought a new hard drive for your computer to be used as a secondary hard drive to store all your files. After installin
    14·2 answers
  • Select the correct answer from each drop-down menu.
    5·2 answers
  • Most of the energy we use originally came from:
    8·1 answer
  • Rewrite the Espresso Counter program to Swap or interchange any two rows of the output. Copy and paste just the interchanged par
    14·1 answer
  • What does Amara hope will<br> happen when Dad sits on the sofa?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!