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 these is an example of a system?
lisov135 [29]

Answer:

force and a single particla of matter

4 0
3 years ago
Write a function named “createPurchaseOrder” that accepts the quantity (integer), the cost per item(double), and the description
Leona [35]
#include
Program: using namespace std;
string createPurchaseOrder0;
int main(
{
cout<return 0;
}
string createPurchaseOrder(
{
int qty;
double costPerltem;
string description,info="":
cout<<"Enter Quantity:
cin>>qty;
cout<<"Enter cost per item: "
cin>>costPerltem;
cout<<"Enter Description: "
cin>>description;
if(qty<0 I| costPerltem<0
Idescription.compare(''"')==0)
cout<<'InThe entered data is invalid!":
info="":
else
"
cout<<"'InThe entered data is valid!":
info=info+"'(nQuantity: "+to_string (qty) +" In";
info=info+"Cost per item:
"†to_string (costPerltem)+"In";
info=info+"Description: "description+" In";
return info;

Output:
4 0
2 years ago
Assuming that all of the table and column names are spelled correctly, what's wrong with the INSERT statement that follows?
Whitepunk [10]

Answer:

C. The number of items in the column list doesn't match the number in the VALUES list.

Explanation:

The INSERT INTO statement is used to insert new records in a table.

<u>Syntax is as follows:</u>

INSERT INTO table_name (column1, column2, column3, ...)

VALUES (value1, value2, value3, ...);

Each column item has to match with the values to be inserted in the same order.

In the question, there are 8 column items specified whereas there are only 7 values given to be inserted.

3 0
3 years ago
Moore's law benefits
ss7ja [257]

Answer:

performance -processor speeds increases because the smaller the transistor, the faster it can operate. Additionally, the transistors become closer to each other which reduces the latency between them.

2.Complexity-for a  given size the number of transistors doubles with the reduction in feature size

Explanation:

3 0
2 years ago
The parts of a memo are _____.
Alex
The correct answer would be D
4 0
3 years ago
Read 2 more answers
Other questions:
  • Being tired has very similar effects on the body as what
    7·1 answer
  • Match the academic requirements with the careers. Technical program , bachelors degree, doctorate degree can go with cosmetologi
    7·2 answers
  • Analog signals consists of individual electric pulses that represents bits group together into bytes {True/False}
    13·1 answer
  • When Clara accesses the programs and documents on her computer by way of icons, she is said to be employing
    15·1 answer
  • Instead of sending an entire file in one big chunk across the​ Internet, __________ is used which dices the file up into little
    12·1 answer
  • How do you know where the home row of the keyboard is?
    14·2 answers
  • Which of the following is a programming language that permits Web site designers to run applications on the user's computer?
    15·1 answer
  • Writing a function that implements a loop to collect a set amount of data. The function should use the serial object, the record
    9·1 answer
  • which of the following devices and and receive information from other device? a parallel port B serial port C video port d both
    8·1 answer
  • What bonnie is this? From five night at freddys
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!