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
A customer states that when she removes the printed pages from her laser printer output tray, the black ink smears all over her
luda_lava [24]

Answer:

B. Fuser unit

Explanation:

Based on the scenario that is being described it can be said that the most likely problem is the Fuser unit. This is a part that plays an important role in the printing process. This unit melts the toner and compresses it in order to leave the impression on the paper with heat. A faulty fuser unit will not compress correctly and leave wet ink on the paper causing it to smear.

7 0
4 years ago
Question 11
STatiana [176]

What type of program would have a class named Student with objects called fullTime and partTime?

A. machine language program

B. object-oriented program

C. markup language program

D. procedural language program

Answer:

B. object-oriented program

Explanation:

An object-oriented program or OOP is a type of program that uses the concepts of objects and methods.

Although they are quite broad, they also make use of classes and types.

Java, for instance makes use of OOP as they use classes and objects under those classes and name them anyhow they want.

Therefore, the correct answer is B

8 0
4 years ago
Here's something random idc
melisa1 [442]

Answer:

ey ey

Explanation:

3 0
3 years ago
Read 2 more answers
In what way can a costume be deleted ?
alex41 [277]

Answer:

Clicking the "X" button towards the upper-right of each costume's icon in the Costume Pane will delete

Explanation:

5 0
3 years ago
All of the following are examples of software, except:
Bezzdna [24]
Speakers is your answer
7 0
3 years ago
Read 2 more answers
Other questions:
  • Did you see the fire, uh, fireworks last night? Which of the following sentences is the most correct way to format this accordin
    15·2 answers
  • 1. _______ is when two things happen at one time when using the Scratch program.
    6·1 answer
  • Five computers are connected to a switch in a star topology. what type of network is this?
    12·1 answer
  • Comparing tools made of stone, iron, and bronze: place them in the correct order from least to most durable
    14·1 answer
  • Which actions help to protect a computer and keep it running properly? Check all that apply.
    10·1 answer
  • Emilio is reviewing the data he collected from historical records about immigration in the united states. He decides to create a
    5·1 answer
  • ____ is a utility that can verify that TCP/IP is installed, bound to the NIC, configured correctly, and communicating with the n
    11·1 answer
  • Which IEEE standards define Wi-Fi technology?
    10·1 answer
  • What does %d, , %c, %s mean and what's their difference?
    12·1 answer
  • Can include the 5-tuple information, which is the source and destination ip addresses, source and destination ports, protocols i
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!