Question

Write Python expressions corresponding to the following statements: The sum of the first five positive integers...

  1. Write Python expressions corresponding to the following statements:
  1. The sum of the first five positive integers
  2. The average age of Sara (age 23), Mark (age 19), and Fatima (age 31)
  3. The number of times 73 goes into 403
  4. The remainder when 403 is divided by 73
  5. 2 to the 10th power
  6. The absolute value of the difference between Sara’s height (54 inches) and Mark’s height (57 inches)
  7. The lowest price among the following prices: $34.99, $29.95, and $3

Homework Answers

Answer #1

Answers:

a) The sum of the first five positive integers

The Answer is (1+2+3+4+5) (or) sum(range(1,6))

Explanation: range() function gives the values from starting value to (n-1). (In our example, it starts at 1 and produces the numbers up to 5)

sum() function sums up the values generated by range() function. (In our example, it is 1,2,3,4,5)

b) The average age of Sara (age 23), Mark (age 19), and Fatima (age 31)

We can find the average by summing up all the numbers, and divide it by number of numbers summed up.

For our example, The Answer is (23+19+31) / 3

c) The number of times 73 goes into 403

We can find the number of times 73 goes into 403, by dividing 403 by 73.

The Answer is 403/73 (or) 403//73 ('/' operator gives fraction where as '//' gives an integer)

d) The remainder when 403 is divided by 73

The operator for finding remainder is %

The Answer is 403 % 73

e) 2 to the 10th power

To calculate the exponent, we use the operator **

The Answer is 2**10

f) The absolute value of the difference between Sara’s height (54 inches) and Mark’s height (57 inches)

The absolute value is calculated by using abs() function. (Absolute value is a positive value)

The Answer is abs(54-57)

g) The lowest price among the following prices: $34.99, $29.95, and $3

Minimum value is calculated by using min() function.

The Answer is min(34.99,29.95,3)

Output Screenshot after executing all the above expressions

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT