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
In which scenario would instant messaging be more useful than other forms of communication?
ivann1987 [24]
When you're busy doing things and/or be too sick for over the phone communication
7 0
3 years ago
_ is a model of computing in which computer processing, storage, software, and other services are provided as a shared pool of v
Jet001 [13]

Answer:

Cloud computing is the correct answer of this question.

Explanation:

Cloud computing presents a easy way of consuming databases, servers, repositories and a vast variety of web technology infrastructure.Cloud computing allows that can save considerable construction costs without relying on internal server resources and device requirements.Cloud computing is the provision of various resources over the Web.

8 0
3 years ago
A new user needs access to their files in iCloud without relying on the operating system (OS). How would the user access the App
m_a_m_a [10]

Answer:

Log in to iCloud.com on a browser

Explanation:

On your browser which should be a supported browser, you should log in to iCloud.com since iCloud is not supported on mac OS X earlier than mac OS X Lion 10.7.5

7 0
3 years ago
What happens when you double-click one of the graphic options in the middle panel of the choose a smartart graphic dialog box?
pickupchik [31]
When you open MS Word, selecting the insert option and clicking SmartArt, will pop up SmartArt dialog box. Double-clicking on one of the graphic options in the middle panel will automatically select and place the graphic art you want. It is an easy way of inserting a SmartArt of your choice without selecting the art itself and clicking OK.





3 0
3 years ago
Read 2 more answers
Kyla, a business analyst uses test scripts while testing an application before it is released to the client. Why do business ana
Mariana [72]

Answer:

D. to create a test environment

Explanation:

After releasing it will be "production"

8 0
3 years ago
Other questions:
  • To use files in a c++ program you must include the ________ header file.
    15·1 answer
  • Why is it difficult to enforce laws against intellectual theft?
    10·1 answer
  • Read each scenario, and then select the best wireless device for the worker’s needs. A trucker is constantly on the road. He fre
    8·2 answers
  • A ____ operating system should be capable of supporting the applications and tools necessary to support Internet operations.
    10·1 answer
  • Angela recently purchased a new Android smartphone. While purchasing the phone, Angela was told that she would need to set up a
    11·1 answer
  • Fill in the blanks. The ________________ donut chart shows the distribution across your website’s pages by the number of clicks
    14·1 answer
  • Which type of storage disk and disk drive can you use in the given situation?
    12·1 answer
  • What are the features of a computer speaker​
    10·1 answer
  • Using a tag, set the color to orange for all tags
    13·2 answers
  • Which is the fastest memory in computer​
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!