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 best describes obliteration in a forged document?
Drupady [299]
The answer is B bc obliteration is related to covering the document
4 0
3 years ago
Tech a says that a direct tpms system uses a pressure sensor located in each wheel
Feliz [49]

Tech a says that a direct tpms system uses a pressure sensor located in each wheel. This is a TRUE statement.

Explanation:

  • A tire-pressure monitoring system (TPMS) is an electronic system designed to monitor the air pressure inside the pneumatic tires on various types of vehicles. A TPMS reports real-time tire-pressure information to the driver of the vehicle, either via a gauge, a pictogram display, or a simple low-pressure warning light.
  • Direct TPMS uses a sensor mounted in the wheel to measure air pressure in each tire. When air pressure drops 25% below the manufacturer's recommended level, the sensor transmits that information to your car's computer system and triggers your dashboard indicator light.
  • Mounted inside a tire assembly on valve stems or wheel rims, the sensors are usually powered by 3-volt lithium ion batteries, but some use 1.25-volt nickel metal hydride batteries. There are developments underway that promise battery-less sensors in the future, having the potential to dramatically change TPMS markets
  • The tire pressure monitor system that uses a valve-stem-type transmitter is the direct reading type of TPMS.

8 0
3 years ago
Meats ages hair and feathers all contain this monomer
OverLord2011 [107]

Answer:Amino Acid

Explanation:

All proteins have amino acids

7 0
2 years ago
Factor completely: 4y^2 - y - 3
notsponge [240]

Answer:

(4y + 3)(y - 1)

Explanation:

4 {y}^{2}  - y  - 3

4 {y}^{2}  - 4y + 3y - 3

4y(y  - 1) + 3(y - 1)

(4y + 3)(y - 1)

7 0
2 years ago
Read 2 more answers
Advantages of desktop publishing over traditional methods include       
Licemer1 [7]
From what my teacher taught us it would be c.
6 0
3 years ago
Other questions:
  • The purpose of the trusted platform module is:
    15·2 answers
  • Define a function below, sum_numeric_vals, which takes a single dictionary as a parameter. The dictionary has only strings for k
    12·1 answer
  • Upon looking out at the
    8·2 answers
  • You've been given a network of 130.0.0.0 /16. you need to divide it into four VLSM subnets as follows:
    8·1 answer
  • wants to redesign the user interface. The customer service agents use ________ to enter explicit statement to invoke operations
    11·1 answer
  • Why must a mobile application be easily customized and personalized?
    14·2 answers
  • Brendan needs to edit all the slides in a presentation by adding a company logo and a header and footer. Which is
    13·2 answers
  • What is the CPU's role?
    15·2 answers
  • Delete temp or %temp% files in Windows 10 is safe and, can it help boost up your PC fps?
    5·1 answer
  • What does command do
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!