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
charle [14.2K]
3 years ago
14

Write a function: function solution(N); that, given a positive integer N, prints the consecutive numbers from 1 to N, each on a

separate line. However, any number divisible by 2, 3 or 5 should be replaced by the word Codility, Test or Coders respectively. If a number is divisible by more than one of the numbers: 2, 3 or 5, it should be replaced by a concatenation of the respective words Codility, Test and Coders in this given order. For example, numbers divisible by both 2 and 3 should be replaced by CodilityTest and numbers divisible by all three numbers: 2, 3 and 5, should be replaced by CodilityTestCoders.
Computers and Technology
1 answer:
koban [17]3 years ago
6 0

Answer:

<em>The program written in Python is as follows:</em>

def solution(N):

     concat = ""

     for i in range(1,N+1):

           if not(i%2 == 0 or i%3 ==0 or i%5 == 0):

                 print(str(i))

           else:

                 if i%2 == 0:

                       concat= concat+"Codility"

                 if i%3 == 0:

                       concat= concat+"Testers"

                 if i%5 == 0:

                       concat= concat+"Coders"

                 print(concat)

                 concat = ""

N = int(input("Enter a positive integer: "))

solution(N)

Explanation:

This line declares the function

def solution(N):

This line initializes a variable named concat to an empty string

     concat = ""

This line iterates from 1 to the input integer

     for i in range(1,N+1):

<em>This line checks if the current number of iteration is divisible by 2,3 or 5, if no, the number is printed</em>

           if not(i%2 == 0 or i%3 ==0 or i%5 == 0):

                 print(str(i))

<em>If otherwise</em>

           else:

<em>This lines checks if current number is divisible by 2; if yes the string "Codility" is concatenated to string concat</em>

                 if i%2 == 0:

                       concat= concat+"Codility"

<em>This lines checks if current number is divisible by 3; if yes the string "Testers" is concatenated to string concat</em>

<em>                 </em> if i%3 == 0:

                       concat= concat+"Testers"

<em>This lines checks if current number is divisible by 2; if yes the string "Coders" is concatenated to string concat</em>

                 if i%5 == 0:

                       concat= concat+"Coders"

<em>The concatenated string is printed using this line</em>

                 print(concat)

This variable concat is intialized back to an empty string

                 concat = ""

The main method starts here

N = int(input("Enter a positive integer: "))

This line calls the defined function solution

solution(N)

You might be interested in
. Which of the following refers to the informal rules for how to behave online? A.
natta225 [31]

Answer:

D.netiquette

hope it is helpful to you

5 0
2 years ago
Write an algorithm to find the area of a parallelogram​
xeze [42]

Answer:

a = bh

Explanation:

a = Area
b = Base

h = Height

8 0
2 years ago
Who say yeet all the time <br><br>Free points
qaws [65]

Answer:

yeet

Explanation:

5 0
3 years ago
Read 2 more answers
Contagem progressiva e regressiva usando estrutura condicional enquanto no visualg
lana [24]
Girls are so evil nowadays
6 0
3 years ago
????????????????????????????????
iris [78.8K]
<h2>Answer:</h2>

(c) 4

<h2>Explanation:</h2>

The function <u>strpos()</u> is a function in php that returns the position of the first occurrence of a particular substring in a string. Positions are counted from 0. The function receives two arguments. The first argument is the string from which the occurrence is to be checked. The second argument is the substring to be checked.

In this case, the string is "Get Well Soon!" while the substring is "Well"

Starting from 0, the substring "Well" can be found to begin at position 4 of the string "Get Well Soon!".

Therefore, the function strpos("Get Well Soon!", "Well") will return 4.

Then, with the echo statement, which is used for printing, value 4 will be printed as output of the code.

6 0
2 years ago
Other questions:
  • Graphic designers sometimes must adjust the spacing between letters so that the result looks right to them. This is called
    12·1 answer
  • What type of analysis should be used to respond to the statement, "Let's cut advertising by $1000 repeatedly so we can see its r
    14·1 answer
  • Token stories of success and upward mobility (illustrated by Oprah, Ross Perot, and Madonna) reinforce ________ and perpetuate t
    8·1 answer
  • When planning a presentation, there are several factors you need to consider. Which of the following is one factor you should co
    8·1 answer
  • .in the array based list implementation of the ADT what is the worst case time efficiency of the getEntry method?
    14·1 answer
  • N, or central processing unit, is also known as the
    10·2 answers
  • Which of the following are documents that can help you to review and assess your organization’s status and state of security? Fi
    6·1 answer
  • What is a Software that interprets commands drom the keyboard and mouse
    13·1 answer
  • You are an IT network administrator at XYZ Limited. Your company has critical applications running of its Ubuntu Linux server. C
    6·1 answer
  • Select all that apply.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!