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
The biggest factor in determining the price of a mortgage is:
Lapatulllka [165]
The interest rate is your answer :)
4 0
3 years ago
What is a block cipher algorithm that operates on 64-bit blocks and can have a key length from 32 to 448 bits?
Deffense [45]

The question has the below multiple choices

A) 3DES
B) RSA
C) Blowfish
D) Twofish


The answer is (C) Blowfish

Also known as the Blow-CAST-Fish, it was designed to run efficiently on 32 bit computers. Up to date no significant weaknesses have been seen. Based on Blow-CAST-Fish, it uses good features of CAST -128[6] algorithms and Blowfish [1]. Features taken from Blowfish [1] algorithm include; S-box entries which are key dependent substitution, varying key lengths of up to 448 bits and procedure of Key expansion


8 0
3 years ago
Which are examples of non-linear presentations? Choose all that apply.
lianna [129]

Answer:

(B) A sales professional writes a presentation for customers to navigate to products of interest.

(D) An instructor selects slides to answer questions from students about the lecture.

Explanation:

answers are for e2020

4 0
3 years ago
What does computer means?
expeople1 [14]

an electronic device for storing and processing data.

4 0
3 years ago
Read 2 more answers
What are the advantages and disadvantages of the various collision resolution strategies for hashes?
Digiron [165]

Linear probing

It does a linear search for an empty slot when a collision is identified

Advantages

Easy to implement

It always finds a location if there is one

Disadvantages

When clusters and keys fill most of the array after forming in adjacent slots of the table, the performance deteriorates

Double probing/hashing

The idea here is to make the offset to the next position probed depending on the key value. This is so it can be different for different keys.

Advantages

Good for double number generation

Smaller hash tables can be used.

Disadvantages

As the table fills up, the performance degrades.

Quadratic probing

It is used to resolve collisions in hash tables. It is an open addressing scheme in computer programming.

Advantage

It is more efficient for a closed hash table.

Disadvantage

Has secondary clustering. Two keys have same probe sequence when they hash to the same location.

6 0
4 years ago
Read 2 more answers
Other questions:
  • Clip art, by default, is formatted as a(n) ____, which cannot be moved to a precise location on a page.
    14·1 answer
  • A person planning to file for bankruptcy must receive credit counseling within two years before filing the petition.
    7·1 answer
  • While in slide show mode, if you are not careful you can close the application by clicking the x on the menu bar. question 38 op
    12·2 answers
  • By placing the chorale melody in the highest voice and using a simple harmonization, bach made it easier for congregation member
    5·1 answer
  • Analog signals consists of individual electric pulses that represents bits group together into bytes {True/False}
    13·1 answer
  • Please help me answer this question
    14·1 answer
  • MULTIPLE CHOICE QUESTION PLEASE HELP!!!!!!!!!
    14·2 answers
  • The pay of an hourly worker is calculated by multiplying the hours worked by the hourly rate—up to 40 hours; any hours worked be
    11·1 answer
  • To indent an entire paragraph or list you should:
    9·1 answer
  • Vẽ sơ đồ DFD cho của hàng bán điện thoại ( Môn phân tích và thiết kế hệ thống thông tin)
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!