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
___ is a career discipline focusing on helping companies use computer technology effectively.
pickupchik [31]

Answer:

A (information technology)

Explanation:

4 0
2 years ago
Software that function as an electronic file cabinet
Airida [17]

Answer:

The answer to this question is "Document management software".

Explanation:

Document management software is software that provides a facility to stores data in an organized manner. It manages and tracks its electronic documents.

  • This software controls many fields, that are Storage location, Security and access control, Version control, etc.
  • It is a common component, that is found in an Enterprise Content Management environment, that uses this software.

7 0
3 years ago
What is the correct keyboard shortcut to cut a cell value
vladimir2022 [97]

Answer:

Cntrl+X

Explanation:

Do it on your computer

4 0
2 years ago
The first step when entering data is _
34kurt

Answer:

click on the cell

Explanation:

This is a little tricky. We need to first think of the column, then of row, and then click on the corresponding cell. And then we either start typing or move our mouse to highlight the cells. Hence, the correct option here is click on the cell.

3 0
3 years ago
What's the main idea??
tatyana61 [14]
My computer wont let me download this pdf

7 0
3 years ago
Other questions:
  • DJ wants to see how his document will look when printed. Where would he find the button to see the document in print view? the P
    5·2 answers
  • Reflexes are basically "hard-wired" into the CNS. Anatomically, the basis of a reflex is an afferent neuron that synapses direct
    10·1 answer
  • An analyst is reviewing the logs from the network and notices that there have been multiple attempts from the open wireless netw
    13·1 answer
  • What is data protection
    13·1 answer
  • Design and implement a class called Sphere that contains instance data that represent the sphere’s diameter. Define the Sphere c
    6·1 answer
  • The objects that you place on master pages are called _____.
    6·1 answer
  • The ___________ method returns the length of an array.
    11·2 answers
  • a user complains he cannot access a particular website, although he is able to access other websites. At which layer of the OSI
    12·1 answer
  • The other term for template document is _______.
    13·2 answers
  • Describe a new career in computer science that may be created in the future
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!