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
Anyone who do bug bounty hunt ?​
lutik1710 [3]

Answer:

Hlo .yes,i have done bug bounty hunt.

5 0
3 years ago
Which of the following is an Internet supervisory protocol? O DNS IP O both A and B O neither A nor B
skelet666 [1.2K]

Answer: Both A and B (DNS and TCP/IP)

Explanation: Internet supervisor protocols are the protocols that  have the supervising standards for the internet functioning. DNS (Domain name system)is the system that supervises the internet by the function of the domain names that is accessed by the user.It acts like phone phone book  that coverts the domain to the IP address.

TCP/IP is the(Transfer control protocol/Internet protocol) are the protocols that help in the function of the internet by providing the connection with the network.The internet runs with help of TCP/IP suite.Thus both, DNS and TCP/IP are supervisory protocol for internet.

6 0
3 years ago
Why do you want to work for Rev?
raketka [301]

People do have reasons why they want to work for a particular company. It may be due to what they company stands for, what they make or about your dream.

I can therefore say that I want to work for Rev because they are revolutionizing the industry and I want to be part of the change process.

<h3>How do you answer why do you want to work?</h3>

Note that when looking for a job, job experience do matter. When ask the reason for looking for this job.

One can answer that they have the experience or the needed expertise and skills required for this job as they want to be aligned with what the company stands for.

Learn more about work  from

brainly.com/question/25573309

7 0
2 years ago
In which format is information stored on a hard drive?
Natalija [7]
The answer is binary
6 0
3 years ago
A customer survey asked respondents to indicate their highest levels of education. The only three choices in the survey were hig
solong [7]

Answer:

27%

Explanation:

100% = 26% + 47% + x%

100% = 73% + x%

27% = x%

4 0
3 years ago
Other questions:
  • Please look at picture
    10·2 answers
  • Find a, b, and c<br> A a=4 square root of 6 b= 8 square root of 2 ; c= 4 square root of 2
    12·1 answer
  • Explain why the game of economics has no winner
    8·1 answer
  • Binary code what does this mean I was sick so I don't under stand
    7·2 answers
  • When you catch an Exception object, you can call ____ to display a list of methods in the call stack so you can determine the lo
    6·1 answer
  • When an item in a menu is black, it means that _____.
    6·2 answers
  • 17. Which of the following keyboard shortcut is used to copy the selected text?
    13·2 answers
  • What are the benefits of computer literacy?
    10·1 answer
  • Explain why you would use the soft on/off jumper when working on ATX system
    14·1 answer
  • A relational database contains a series of _____ that can be connected to form relationships.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!