Faculty of Engineering and Mathematical Sciences 
Not logged in (login)


This forum is provided to promote discussion amongst students enrolled in Computational Thinking with Python (CITS1401).
Jump to:

Not able to understand the question

1 of 3 articles shown, currently no other people reading this forum.
From: Edward A.
Date: Mon 23rd Mar 2020, 7:09pm


"Rishee Barthakur" <22*9*6*[email protected]*u*e*t*u*a*e*u*a*> wrote:

> Write a function composite2(N) which takes an integer N as an input and returns the 
> Nth composite number which is NOT divisible by 2. For instance, composite2(3) returns 
> 21 while composite2(5) returns 27.  

I don't have access to your labsheet, so forgive me if I'm repeating information that you already know. 

When faced with a problem I don't understand I find it's important to think about the elements of the problem and try to follow along with an example. 

So let's start off first with the definition of a composite number (I've taken this one from Wikipedia):

>"A composite number is a positive integer that can be formed by multiplying two smaller >positive integers. Equivalently, it is a positive integer that has at least one divisor >other than 1 and itself."

So, a composite n is a number for which the following conditions hold:
1. n is not prime.
2. n is not 1.

So a function generating the nth composite would simply find the nth number which is not 1 or prime. 

Given that you are writing a function called composite2 I can only assume you've written a function composite which generates the nth composite number. 

If that is the case composite2 need only add the condition that any composite n is not divisible by 2. 

To do this should be relatively trivial. I suggest you look into the modulus operator (%) in programming and how it can be used to check if a number is divisible by two. 

Hope that helps! 

Related articles

Not able to understand the question (both) RSS
├─ original   Mon 23rd Mar 2020, 2:41pm, Rishee B.
└─ THIS   Mon 23rd Mar 2020, 7:09pm, Edward A.
This Page

Program written by: [email protected]
Feedback welcome
Last modified:  9:57am Nov 18 2020