[Tutor] Tutor Digest, Vol 196, Issue 30
Alan Gauld
alan.gauld at yahoo.co.uk
Tue Jun 16 04:05:51 EDT 2020
First, please do not send the entire digest. We have all seen these
messages already and some people pay for their data by the byte.
Also it is better to send code in-line (using plain text format)
since the server strips attachments which it deems security threats.
On 16/06/2020 04:22, Krish P via Tutor wrote:
> please check the code, I am finding it difficult to open the data file to read data from it
The code is a syr() function that should work.
But it makes no attempt to open a file, read
the contents or process the data.
The previous program code opened the file and printed it.
You need to store the data and split it into its
constituent numbers.
But we can only help you fix code that we can see.
It's impossible to guess what you are doing wrong if
we can't see the code that is broken.
I've included your function below for the archive.
#################################
def printCollatz(x):
# We simply follow steps
# while we do not reach 1
while x != 1:
print(x, end = ' ')
# If x is odd
if x & 1:
x = 3 * x + 1
# If even
else:
x = x // 2
# Print 1 at the end
print(x)
##############################
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list