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
satela [25.4K]
3 years ago
9

Write a function in python that computes and returns the sum of the digits for any integer that is between 1 and 999, inclusive.

Use the following function header: def sum_digits(number): Once you define your function, run the following examples: print(sum_digits(5)) print(sum_digits(65)) print(sum_digits(658)) Note: Do not hard-code your function. Your function should run for any number between 1 and 999. Your function should be able to decide if the number has 1 digit, 2 digits, or 3 digits.
Computers and Technology
1 answer:
DanielleElmas [232]3 years ago
3 0

Answer:

def sum_digits(number):

   total = 0

   if 1 <= number <= 999:

       while number > 0:

           r = int (number % 10)

           total +=r

           number /= 10

   else:

       return -1

   return total

   

print(sum_digits(658))

Explanation:

Write a function named sum_digits that takes one parameter, number

Check if the number is between 1 and 999. If it is, create a while loop that iterates until number is greater than 0. Get the last digit of the number using mudulo and add it to the total. Then, divide the number by 10 to move to the next digit. This process will continue until the number is equal to 0.

If the number is not in the given range, return -1, indicating invalid range.

Call the function and print the result

You might be interested in
Binary search requires that data to search be in order. true or false
Iteru [2.4K]
<span>Binary search requires that data to search be in order.
The answer is true
Hope this help!!</span>
5 0
3 years ago
In cell I8, enter a nested logical function to display Need to Remodel if the apartment is unoccupied (No) AND was last remodele
galina1969 [7]

Answer:

The Function is given as

=IF(AND(E8="No",G8>10),"Need to remodel","No Change")

Explanation:

The syntax of the IF condition in excel is given as

IF(Test,If true,If false)

So here the test is an and component such that the house has to be unoccupied which is indicated as E8 because the E column contain the occupancy of the apartments, and the G8 is the last remodeling time, so the test statement is the AND operation of the conditions as

E8="No" indicating that house is unoccupied

G8>10 indicating that the last remodelling was more that 10 years ago

So the test is given as

AND(E8="No",G8>10)

Now the statement if the test true is the recommendation for to remodel, so

"Need to remodel"

Now the statement if the test is false is given as

"No Change"

So the overall function becomes

=IF(AND(E8="No",G8>10),"Need to remodel","No Change")

3 0
2 years ago
What is the Is option that prints the author of a file​
sleet_krkn [62]

Answer:

Print.. is your answer...

4 0
3 years ago
This is the most flexible way to create a query. Used to create queries that displays only the records that match criteria enter
Pachacha [2.7K]

Answer:

Query Wizard

Explanation:

We can use the Query Wizard to automatically create a selection query, but in this case, we have less control in our details of the query design, it's the fastest way to create a query, even detect some design errors.

Steps to use the Query Wizard

1) In the Queries group on the Create, click Query Wizard

2) Add fields

3) On the last page of the wizard, add a title to the query

6 0
3 years ago
What is the term for the era created by the digital revolution?
ollegr [7]
We are in the modern era and the information era
8 0
3 years ago
Other questions:
  • Peter wants to submit his admission form online. What type of input element will allow him to enter his last name on the web pag
    6·1 answer
  • A name given to a spot in memory is called:
    5·1 answer
  • If you are driving at night, you should not use high-beam headlights within _________ of oncoming vehicles. Florida Road Rules 4
    9·2 answers
  • What is industry 4.0 -automation revolution-, what is your opinion about the direction this revolution is taking the industry in
    8·1 answer
  • In python:
    14·1 answer
  • What is one method that can be used to open the Microsoft Word application?
    8·1 answer
  • The 8-bit ____ field is used by source network hosts and forwarding routers to distinguished classes or priorities in ipv6 packe
    11·1 answer
  • You were recently hired by a small start-up company. The company is in a small office and has several remote employees. You have
    15·1 answer
  • Where would you go to access frequently used icons?
    12·2 answers
  • Computers rarely make mistakes. True or false
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!