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 property describes if a mineral breaks down into flatpieces​
marta [7]

Answer: Cleavage

Explanation:

3 0
3 years ago
An intruder can wreak havoc on a network by simply plugging in an infected USB flash drive.
Bas_tet [7]

Answer:

A. True

Explanation:

1. I took the test

2. Flash drive ports are connected to the rest of the computer, so putting in an infected flash drive into the port will cause the bug to spread throughout the whole device.

3 0
2 years ago
Robots are increasingly being used in caring roles. Discuss the ethical and cultural implications of this trend
vekshin1
Using more robots means less human contact which means declining social skills, and heavier dependence on technology. And using more technology is expensive.
4 0
3 years ago
Ergonomia este știința care studiază ....
maria [59]

Answer:

Ergonomia (sau factorii umani) este disciplina științifică preocupată de înțelegerea interacțiunilor dintre om și alte elemente ale unui sistem și profesia care aplică teorie, principii, date și metode pentru a proiecta pentru a optimiza bunăstarea umană și în general performanta sistemului."

Explanation:

4 0
3 years ago
Please list of 15 safety rules that you think should be practiced in the Computer Technology classroom/lab.
geniusboy [140]

Answer:

BE RESPECTFUL! Always treat the computer lab equipment AND your teacher and classmates the way that you would want your belongings and yourself to be treated.

No food or drinks near the computers. NO EXCEPTIONS.

Enter the computer lab quietly and work quietly. There are other groups and individuals who may be using the computer lab. Please be respectful.

Surf safely! Only visit assigned websites. Some web links can contain viruses or malware. Others may contain inapropriate content. If you are not certain that a website is SAFE, please ask a teacher or other adult.

Clean up your work area before you leave. All cords should be placed on the tables (not hanging off the sides). Headphones should be placed on the CPU/tower or monitor. Chair should be pushed under the tables. All trash, papers, and pencils should be picked up.

Do not change computer settings or backgrounds.

Ask permission before you print.

SAVE all unfinished work to a cloud drive or jump drive. Any work that is saved to the computer will be deleted when the computer is powered off or updated at the end of the day.

If you are the last class of the day, please POWER DOWN all computers and monitors.

Explanation:

tick me as brainlilist please

3 0
2 years ago
Other questions:
  • Investments in data networks, ip addresses, routers, and switches are ________ because of their impact on productivity, security
    14·1 answer
  • What is the best information to include in the template name to differentiate it from other templates? Check all that apply.
    6·1 answer
  • What happens it the offshore team members are not able to participate in the iteration demo due to time zone/infrastructure issu
    11·1 answer
  • You have a notebook computer and wish to connect to an IEEE 802.11ac wireless network. The computer does not have a built-in WLA
    15·1 answer
  • A 5-stage MIPS pipeline has a register file without forwarding mechanism. How many NOPs (or bubbles) will you need to add to mak
    9·1 answer
  • The game often becomes stuck on landscape mode when tilting the device during gameplay, which cuts off some peripheral text. A w
    8·1 answer
  • Krya needs help deciding which colors she should use on her web page. What can she use to help her decide.
    11·1 answer
  • Mention 3 components that can be found at the back and front of the system unit​
    6·1 answer
  • Is this App for real?​
    5·1 answer
  • Que es una red de datos
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!