Ad
Mathematics

Problem: Subtract Seven Until Zero

Write a function numMinusSeven(num) that takes a number as an argument. The function should subtract seven from the given number until the result is less than or equal to zero. The function should return the number of times seven could be subtracted.

For example:

If the given number is 1000, the function should return 143 because you can subtract seven 143 times before getting a number less than or equal to zero.
If the given number is 100, the function should return 15.
If the given number is 10, the function should return 2.

Code
Diff
  • function numMinusSeven(num) {
      return Math.ceil(num / 7);
    }
    • function numMinusSeven(num) {
    • let arr = []
    • while (num > 0) {
    • num -= 7
    • arr.push(num)
    • }
    • return arr.length
    • }
    • return Math.ceil(num / 7);
    • }
Code
Diff
  • print("hello", 7, sep='\n')
    • print("hello\n" + str(7))
    • print("hello", 7, sep='\n')