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
In MS Word we can merga cells true or false​
sergey [27]
In this video I showed you all of the locations for all items in Wacky Wizards!! I hope you enjoyed and please like and subscribe. Piece out!!!
7 0
2 years ago
Read 2 more answers
What is a type of transition used for music in Earsketch
Grace [21]

Answer:

In order to compose music, EarSketch coders can use samples. Audio samples are located in the sound browser, in the left window, which allows for sound file search, and personal sound file upload. In the left section, users can also show the script browser.

No account is required to create projects or view existing projects. EarSketch comprises different elements: a curriculum, a digital audio workstation (or DAW), a code editor and console, and a sound browser.

Dissolves The dissolve is probably the most used transition in video editing. Also known as a cross-dissolve, this effect layers two clips together so there is a seamless transition from one picture to another. You see it everyday and probably don’t even notice it: and that’s the point.

Explanation:

EarSketch is web-based, which means users can access it with their web-browsers, and with no installation. No account is required to create projects or view existing projects. EarSketch comprises different elements: a curriculum, a digital audio workstation (or DAW), a code editor and console, and a sound browser.

8 0
2 years ago
The _____ constraint assigns a value to an attribute when a new row is added to a table
bixtya [17]

The default constraint gives a value to an attribute when a new row is added to a table.

<h3>Is default a kind of constraint?</h3>

This is known to be a type of constraint that often apply a value to a column if an INSERT statement does not really give the value for the column.

Therefore, one can say that the default constraint gives a value to an attribute when a new row is added to a table.

Learn more about default constraint from

brainly.com/question/19130806

#SPJ12

5 0
2 years ago
Which peripheral device is used to record sound?
faust18 [17]

he will need a microphone, it is a recording device.

8 0
2 years ago
Read 2 more answers
The number of __________ to your website that had not visited prior to the time frame being analyzed.
liq [111]

Answer:

First Time Unique Visitor

Explanation:

I majored in

4 0
2 years ago
Other questions:
  • Explain how buyers and sellers factor into setting the stock price for a company’s shares.
    13·1 answer
  • The acronym is used to define the process that allows multiple devices to share a single routable ip address.
    6·1 answer
  • "Suppose that instead of always selecting the first activity to finish, we instead select the last activity to start that is com
    14·1 answer
  • Create a simple main() that solves the subset sum problem for any vector of ints. Here is an example of the set-up and output. Y
    12·1 answer
  • Which of the following is not an example of technological progress? A: new scientific knowledge that has practical applications
    12·2 answers
  • 6. While using the HTS, ________________ will help maintain a safe driving environment despite high speeds and a large number of
    12·1 answer
  • . Business-to-business integration (B2Bi) is vital for efficient and accurate flow of data across internal ISs and external busi
    11·1 answer
  • Is your florida learners license number the same as the actual license number?
    14·2 answers
  • Which option is an example of a Boolean operator?<br> O A. HTML<br> O B. <br> C. SEO<br> D. NOT
    5·1 answer
  • How would you define the term technology
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!