# Newbie - Trying to Help a Friend

B

Hi,

A Friend is doing maths in University and has had some coursework to do with python.

The question is

"Write a program that calculates how many positive integers less than N arenot divisible by 2,3 or 5. The user should be prompted to supply the Number N. Demonstrate your program output when the input N is your student id. (13006517)

"The collatz process is as follows. Take a positive integer n greater than 1. while n is greater than 1 repeat the following; if N is even halve it and if N is odd multiply it by 3 and add 1. The (Unsolved) collatz conjectureis that this process always terminates.

The user should be prompted to supply the number n, and your program shouldbuild the list of values taken by sucessive iteration of the algorithm, and print it out. For example, if 7 is input your program should print the list

[7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1]

Demonstrate your program output for an input value consisting of the numberformed adding 10 to the last digit of your student id. (13006517)"

Any help would be appreciated

M

#### maxwell34m

Hi,

A Friend is doing maths in University and has had some coursework to do with python.

The question is

"Write a program that calculates how many positive integers less than N are not divisible by 2,3 or 5. The user should be prompted to supply the Number N. Demonstrate your program output when the input N is your student id.(13006517)

"The collatz process is as follows. Take a positive integer n greater than 1. while n is greater than 1 repeat the following; if N is even halve it and if N is odd multiply it by 3 and add 1. The (Unsolved) collatz conjecture is that this process always terminates.

The user should be prompted to supply the number n, and your program should build the list of values taken by sucessive iteration of the algorithm, and print it out. For example, if 7 is input your program should print the list

[7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1]

Demonstrate your program output for an input value consisting of the number formed adding 10 to the last digit of your student id. (13006517)"

Any help would be appreciated

I'm pretty sure this is not a group for helping people cheat on their school coursework.

You,the one trying to supposedly help him couldn't even write a single lineof code. How is that "helping"?

Kindly come back when u've done some real work and you are stuck.

I hope I've been of "help" to you and your friend.

thanks

G

#### Gary Herron

Hi,

A Friend is doing maths in University and has had some coursework to do with python.

The question is

"Write a program that calculates how many positive integers less than N are not divisible by 2,3 or 5. The user should be prompted to supply the Number N. Demonstrate your program output when the input N is your student id. (13006517)

"The collatz process is as follows. Take a positive integer n greater than 1. while n is greater than 1 repeat the following; if N is even halve it and if N is odd multiply it by 3 and add 1. The (Unsolved) collatz conjecture is that this process always terminates.

The user should be prompted to supply the number n, and your program should build the list of values taken by sucessive iteration of the algorithm, and print it out. For example, if 7 is input your program should print the list

[7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1]

Demonstrate your program output for an input value consisting of the number formed adding 10 to the last digit of your student id. (13006517)"

Any help would be appreciated

What sort of help are you requesting? We're not in the habit of writing
student assignments for them because they will learn nothing from such
an effort.
attempt on the assignment. If he gets stuck, he may ask a specific
Python question. I'm sure lots of help will follow.

As a side note, these are extremely simple beginner problems, each
requiring only a few lines of code. Any programming class that assigned
these must have included some lectures on the basics of programming.
That's where he should start.

Gary Herron

N

#### Neil Cerutti

A Friend is doing maths in University and has had some
coursework to do with python.

The question is

"Write a program that calculates how many positive integers
less than N are not divisible by 2,3 or 5. The user should be
prompted to supply the Number N. Demonstrate your program
output when the input N is your student id. (13006517)

"The collatz process is as follows. Take a positive integer n
greater than 1. while n is greater than 1 repeat the following;
if N is even halve it and if N is odd multiply it by 3 and add
1. The (Unsolved) collatz conjecture is that this process
always terminates.

The user should be prompted to supply the number n, and your
program should build the list of values taken by sucessive
iteration of the algorithm, and print it out. For example, if 7
is input your program should print the list

[7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1]

Demonstrate your program output for an input value consisting
of the number formed adding 10 to the last digit of your
student id. (13006517)"

Any help would be appreciated

What has A Friend written so far? Where are you stuck?

--
Neil Cerutti

Hi,

A Friend is doing maths in University and has had some coursework to do with python.

The question is

"Write a program that calculates how many positive integers less than N are not divisible by 2,3 or 5. The user should be prompted to supply the Number N. Demonstrate your program output when the input N is your student id.(13006517)

"The collatz process is as follows. Take a positive integer n greater than 1. while n is greater than 1 repeat the following; if N is even halve it and if N is odd multiply it by 3 and add 1. The (Unsolved) collatz conjecture is that this process always terminates.

The user should be prompted to supply the number n, and your program should build the list of values taken by sucessive iteration of the algorithm, and print it out. For example, if 7 is input your program should print the list

[7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1]

Demonstrate your program output for an input value consisting of the number formed adding 10 to the last digit of your student id. (13006517)"

Any help would be appreciated

B

Hi,

A Friend is doing maths in University and has had some coursework to do with python.

The question is

"Write a program that calculates how many positive integers less than N are not divisible by 2,3 or 5. The user should be prompted to supply the Number N. Demonstrate your program output when the input N is your student id.(13006517)

"The collatz process is as follows. Take a positive integer n greater than 1. while n is greater than 1 repeat the following; if N is even halve it and if N is odd multiply it by 3 and add 1. The (Unsolved) collatz conjecture is that this process always terminates.

The user should be prompted to supply the number n, and your program should build the list of values taken by sucessive iteration of the algorithm, and print it out. For example, if 7 is input your program should print the list

[7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1]

Demonstrate your program output for an input value consisting of the number formed adding 10 to the last digit of your student id. (13006517)"

Any help would be appreciated

Think they just needed a starting point really to be honest as they can't get there head round it.

That was all. Badly worded this, wasn't looking for someone to do it all for him apologies

D

#### Denis McMahon

Think they just needed a starting point really to be honest as they
can't get there head round it.

First of all there seems to be two problems, not 1.

Here are some steps for each of the calculations. Any resemblance of
these steps to actual program code is due to my not bothering to
obfuscate the statement and function names more than I did.

1) Find all the numbers less than n that are not divisible by a, b, or c.

assign the value 0 to some other variable i;
while i is not greater than than x do the following [
if i is not divisible by a and i is not divisible by b and i is not
divisible by c then display i to the user;
]

2) Find the collatz sequence for x.

ask the user for initial x;
while x is not 1 {
if x is divisible by 2 [ new x = perform even number collatz math on x; ]
otherwise [ new x = perform odd number collatz math on x; ]
display new x to the user;
}

M

#### Mark Janssen

Think they just needed a starting point really to be honest as they can't get there head round it.

Then the problem is that your friend doesn't understand one or more of
the words being used. This is s necessary prerequisite for making an
algorithm from a text description. Perhaps they don't know what it
means to be "divisible".

S

#### Steven D'Aprano

Hi,

A Friend is doing maths in University and has had some coursework to do
with python.

The question is

"Write a program that calculates how many positive integers less than N
are not divisible by 2,3 or 5. The user should be prompted to supply the
Number N. Demonstrate your program output when the input N is your
student id. (13006517)

Have your friend start by writing down how she or he would solve this
problem by hand. I'll get you started by solving the problem for 7.

Positive integers less than 23 are 1, 2, 3, 4, 5, 6. So let's start
checking them for divisors:

- 1 is not divisible by 2, 3 or 5, so we count one number.
- 2 is divisible by 2, but not by 3 or 5, so we count two numbers.
- 3 is not divisible by 2, so we count three numbers.
- 4 is divisible by 2, but not 3 or 5, so we count four numbers
- 5 is not divisible by 2, so we count five numbers.
- 6 is divisible by 2 and 3, but not by 5, so we count six numbers.

Now that you know what you yourself would do to solve this problem, the
next step is to write it in terms that a computer can understand. A few
hints:

1) You can check divisibility by using the % operator, which returns the
remainder after division. So 36 % 6 gives 0, which means that 36 is
divisible by 6. 37 % 6 gives 1, which means 37 is not divisible by 6.

2) You can use "for i in range(1, N)" to generate the positive integers
less than N.

3) You can use the "or" operator to efficiently check multiple
conditions. For example, this line of code:

if (a % 2) or (a > 16):

checks whether a number a is either an odd number or larger than sixteen,
and if so runs the indented block of code following (not shown).

4) You can prompt the user for a value using the input (Python 3) or
raw_input (Python 2) function. For example, using Python 2:

result = raw_input("Enter a number between 3 and 12: ")

lets the user type in anything in response. That result will be a string,
to convert it to a number:

result = int(result)

5) You can create a variable and initialise it to some value like this:

count = 0

creates a variable called "count", set to the value 0. You can then add
one to it like this:

count = count + 1

or if you prefer:

count += 1

Either way adds one to count.

I expect that the above should be enough to get your friend started and
possibly even finished. If she/he gets stuck, come back with some code
and specific questions.

Good luck!

D

#### Dave Angel

problem by hand. I'll get you started by solving the problem for 7.

Positive integers less than 23 are 1, 2, 3, 4, 5, 6. So let's start
checking them for divisors:

Where did 23 come from?

- 1 is not divisible by 2, 3 or 5, so we count one number.
- 2 is divisible by 2, but not by 3 or 5, so we count two numbers.

2 doesn't count because it's divisible by 2.
- 3 is not divisible by 2, so we count three numbers.

3 doesn't count because it's divisible by 3
- 4 is divisible by 2, but not 3 or 5, so we count four numbers

And so on.
- 5 is not divisible by 2, so we count five numbers.
- 6 is divisible by 2 and 3, but not by 5, so we count six numbers.

I count 1, not 6

S

#### Steven D'Aprano

Where did 23 come from?

Sorry, first draft of this post was going to go up to 23.

2 doesn't count because it's divisible by 2.

2 does count because it isn't divisible by 3. The question states,
"[count] how many positive integers less than N are not divisible by 2,3
or 5". Two is not divisible by 3, so "not divisible by 2,3 or 5" is true,
so two gets counted.

The first number which is divisible by *all* of 2, 3 and 5 (i.e. fails
the test, and therefore doesn't get counted) is 30. The next few that
fail the test are 60, 90, 120, 150, 180, 210, 240, 270, 300, ...
Remember, these are the numbers which should not be counted.

I count 1, not 6

Out of curiosity, which number did you count?

D

#### Dave Angel

2 does count because it isn't divisible by 3. The question states,
"[count] how many positive integers less than N are not divisible by 2,3
or 5". Two is not divisible by 3, so "not divisible by 2,3 or 5" is true,
so two gets counted.
The first number which is divisible by *all* of 2, 3 and 5 (i.e. fails
the test, and therefore doesn't get counted) is 30. The next few that
fail the test are 60, 90, 120, 150, 180, 210, 240, 270, 300, ...
Remember, these are the numbers which should not be counted.
Out of curiosity, which number did you count?

1 of course. It's the only one that's not divisible by any of the
factors.

Apparently we disagree about precedence and associativity in English.
I believe the not applies to the result of (divisible by 2, 3, or 5),
so I'd count 1, 7, 11, 13, 17, 19, 23. The first nonprime would be
49.

If I were trying to get the series you describe, I'd phrase it as
"Not divisible by 2, and not divisible by 3, and not divisible by 5"

C

#### Chris Angelico

I don't think the problem is at my end. I am only sending once to the
best of my knowledge

Exactly four again.

https://mail.python.org/pipermail/python-list/2013-November/660769.html
https://mail.python.org/pipermail/python-list/2013-November/660770.html
https://mail.python.org/pipermail/python-list/2013-November/660771.html
https://mail.python.org/pipermail/python-list/2013-November/660772.html

Might be a problem with the mail<->news gateway, or might be that
something's sending through by multiple routes for redundancy. The
timestamps differ, not sure if that helps track it down.

ChrisA

C

#### Chris Angelico

must be a strange quirk of pan & turned off hide to system tray & allow
multiple instances.

Hmm. Hard to know, but I can imagine that having multiple instances
MIGHT cause a problem. But if that's confirmed (maybe fire up three
copies and then post to a test newsgroup??), I'd be reporting that as
a bug in Pan.

ChrisA

N

#### Ned Batchelder

Three. You're not Greek are you, and using a typical shabby Nazi trick
to hide behind an ntlworld email address in order to spam us?

Mark Lawrence

Nazi? Perhaps we could stick to more appropriate analogies?

--Ned.

N

#### Ned Batchelder

It's an excellent analogy that I've used before, hence the smiley.
Clearly you don't do any research before bothering to say anything.

--
Python is the second best programming language in the world.
But the best has yet to be invented. Christian Tismer

Mark Lawrence

You think these two things make an excellent analogy? 1) a newsgroup mishap being actively investigated, and 2) calculated genocide. It is not an excellent analogy, it's wildly disproportionate.

Using a smiley doesn't fix it, and using it previously doesn't give you a free pass. What research was I supposed to have done? Examine your previous posts to see you overreacting before? That would hardly have convinced me that this was OK.

--Ned.

N

#### Ned Batchelder

I suggest that you write to the BBC and get all episodes of the
extremely popular *COMEDY* "Dad's Army" withdrawn as "typical shabby
Nazi trick" was one of Captain Mainwearing's main lines.

I see what you are getting at. You were referring to a TV show popular in your part of the world 30 years ago. As this is a world-wide group, you might understand that I didn't get the reference, and perhaps many others did not either. Humor is tricky, you need to know your audience.
And if I want
to overreact, I'll overreact, as I couldn't care two hoots whether I'm
dealing with an arsehole from the Python Software Foundation or one
who's not.

I have no idea why you feel the need to insult me. As to the PSF, this is relevant: http://www.python.org/psf/codeofconduct. "Members of the community are respectful." Could you please be?

--Ned.

N

#### Ned Batchelder

It was 45 years ago, at very much the same time that another very
popular comedy was on, but its name escapes me right now.

You mean after I had to plonk you from my own email because you kept
sending messages despite the fact that I'd asked you not to. So the
references above only apply to me but not to you? You bloody two faced
hypocrite, excuse me while I go off and barf.

Mark Lawrence

I apologize for sending you off-list emails. I'm still baffled why you find them so objectionable, but I won't do it any more. I often send emails to people when I want to communicate privately with them, I didn't mean any offense.

Next time someone doesn't understand one of your jokes, perhaps you could simply explain the joke, rather than calling them an "arsehole". Or I guessyou were already angry with me, and others would have been treated better.My membership in the PSF seems to irritate you, but again, I don't know why.

--Ned.

C

#### Chris Angelico

I see what you are getting at. You were referring to a TV show popular inyour part of the world 30 years ago. As this is a world-wide group, you might understand that I didn't get the reference, and perhaps many others did not either. Humor is tricky, you need to know your audience.

The solution is really quite simple. The insertion of a single
footnote will do it. Let it stand that every obscure reference is
explained after your signature, and there you are, out of your
difficulty at once! [1]

ChrisA

[1] See Gilbert & Sullivan's "Iolanthe", eg
http://math.boisestate.edu/gas/iolanthe/web_op/iol23d.html

D

#### Dennis Lee Bieber

I don't think the problem is at my end. I am only sending once to the
best of my knowledge

Does Pan have an option to generate its own Message-ID header?

Headers seem to indicate multiple injections somewhere

Original-Path:
vs
Original-Path:

Message-ID: <R%[email protected]>
vs
Message-ID: <n%[email protected]>

fx04.am4 vs fx07.am4

S

#### Steven D'Aprano

I for one *have* done extensive research on the Nazis, not to a
professional academic standard, but certainly to the point where I like
to flatter myself that I know a thing or two about them, their political
philosophy, and their actions. I must say that your analogy "multiple
postings to a newsgroup implies Nazi" perplexes me too.

[...]
I suggest that you write to the BBC and get all episodes of the
extremely popular *COMEDY* "Dad's Army" withdrawn as "typical shabby
Nazi trick" was one of Captain Mainwearing's main lines.

I fully support the right of everyone to make cryptic references to
movies, television shows, science fiction and fantasy novels, internet
memes, and assorted pop culture references. Offler knows I've done it
myself. But, if the reference falls flat, or worse is misunderstood, and
sometimes they will, can I suggest there are two appropriate responses?

1) Sheepish apology for making a reference too obscure, e.g.:

Oh, sorry, I was quoting Captain Mainwearing's catchphrase
from "Dad's Army", it isn't intended to imply that Alister is
an actual goose-stepping fascist who believes a lot of racial
pseudo-scientific rubbish.

2) Incredulity that anyone might have missed the reference, e.g.:

What? How can anyone not recognise that reference? Everyone I
know in the UK over the age of 60 loves the show "Dad's Army"!
This is one of the funniest lines from it! Oh how me dear ol'
mum used to laugh every time Captain Mainwearing said it!

(Listen very carefully, I shall say this only once. I'm more of a 'Ello
'Ello person myself.)

And if I want
to overreact, I'll overreact, as I couldn't care two hoots whether I'm
dealing with an arsehole from the Python Software Foundation or one
who's not.

This, however, is very rarely an appropriate response for anyone over the
age of two.

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

### Members online

No members online now.

473,610
Messages
2,568,996
Members
44,095
Latest member
Opalite