189k views
0 votes
Majken is turning 18 years old soon and wants to calculate how many seconds she will have been alive.

Her code looks like this:
numYears ← 18
secondsInDay ← 60 * 60 * 24
Which code successfully calculates and stores the total number of seconds?
️Note that there may be multiple answers to this question.
Choose all answers that apply:
Choose all answers that apply:

(Choice A)
A
totalSeconds ← secondsInDay * 365 * numYears

(Choice B)
B
totalSeconds ← numYears * 365 * secondsInDay

(Choice C)
C
totalSeconds ← secondsInDay * 365 % numYears

(Choice D)
D
totalSeconds ← secondsInDay / 365 / numYears

(Choice E)
E
totalSeconds ← secondsInDay * 365 + numYears

(Choice F)
F
totalSeconds ← (numYears * 365) * secondsInDay

User TheNotMe
by
4.3k points

2 Answers

5 votes

Answer:

I choose D :)

Step-by-step explanation:

User Jase Whatson
by
3.8k points
6 votes

The correct choices are A, B, and F.

totalSeconds ← secondsInDay * 365 * numYears. This choice correctly calculates the total number of seconds by multiplying the number of years, days in a year, and seconds in a day.

totalSeconds ← numYears * 365 * secondsInDay. This choice is also correct and equivalent to Choice A. It correctly multiplies the number of years, days in a year, and seconds in a day.

totalSeconds ← secondsInDay * 365 % numYears. This choice is incorrect because the % operator is the modulus operator, and it doesn't calculate the total number of seconds. It calculates the remainder when dividing by numYears.

User Charles Annic
by
3.9k points