[Tutor] Tutor Digest, Vol 196, Issue 30

Krish P krishp52 at rocketmail.com
Mon Jun 15 23:22:54 EDT 2020

``` please check the code, I am finding it difficult to open the data file to read data from it and then finding the Syracuse sequence
Please see the data and code attached
On Tuesday, June 16, 2020, 04:00:22 AM GMT+12, tutor-request at python.org <tutor-request at python.org> wrote:

Send Tutor mailing list submissions to
tutor at python.org

To subscribe or unsubscribe via the World Wide Web, visit
https://mail.python.org/mailman/listinfo/tutor
or, via email, send a message with subject or body 'help' to
tutor-request at python.org

You can reach the person managing the list at
tutor-owner at python.org

than "Re: Contents of Tutor digest..."

Today's Topics:

1. Re: Tutor Digest, Vol 196, Issue 28 (Alan Gauld)
2. Re: i want a solution to my problem (David Rock)

----------------------------------------------------------------------

Message: 1
Date: Mon, 15 Jun 2020 12:16:04 +0100
From: Alan Gauld <alan.gauld at yahoo.co.uk>
To: tutor at python.org
Subject: Re: [Tutor] Tutor Digest, Vol 196, Issue 28
Message-ID: <rc7l9k\$dql\$1 at ciao.gmane.io>
Content-Type: text/plain; charset=utf-8

On 15/06/2020 02:34, Krish P via Tutor wrote:
>  Hi, thanks for your response.
> I not able to?generate the Syracuse sequence for each of those numbers in the data.txt file.
> given is the code that I came up with:
> def syr(x):? ? if x % 2 ==0:? ? ? ? return x/2? ? else:? ? ? ? return 3*x + 1??def main():? ? x = 50? ? print(x*"-") # Line Break (LB)? ? print("Program use Syracuse sequence to reach 1 from")? ? print("natural numbers by utilizing a set of data.")? ? print(x*"-") # LB
> ? ? f = open("data.txt", "r")? ? print(f.read())
> ? ??main()

You need to post in plain text or the mail server screws up the
indentation as above.

However, even with that I have some questions:

main() isn't really a main function it just prints a banner message,
so calling it print_banner() or somesuch would make more sense.

Where is the code that reads each number (or even a single number!)
from the data file? the f.read() call will read the whole file into
a string but after you print it it disappears because you don't
store it anywhere.

I would expect your code structure to look like:

print banner
for each entry in data
call syr() function on each data entry
store and print result

If you don't know how to do any of that let us know.

HTH

--
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

------------------------------

Message: 2
Date: Mon, 15 Jun 2020 08:34:23 -0500
From: David Rock <david at graniteweb.com>
To: tutor at python.org
Subject: Re: [Tutor] i want a solution to my problem
Message-ID: <20200615133423.GA29904 at apple.graniteweb.com>
Content-Type: text/plain; charset=us-ascii

* Chirag Jain <jtarun960 at gmail.com> [2020-06-15 08:31]:
> module 'sqlite300.sqlite3' has no attribute 'connect'

As others have mentioned, we need more information/code to give an accurate
assessment, but that particular message essentially means you have tried to use
the following in some way:

sqlite300.sqlite.connect

and "connect" is not something contained in sqlite300.sqlite3, so it
fails.  A sample of your code using the above statement will help a lot
in our understanding.

You will need to look at the documentation of the module you are using
(preferably with a link so we can look at it, too), or give us a full
traceback (not just the last line of error) for us to guide further.

--
David Rock
david at graniteweb.com

------------------------------

Subject: Digest Footer

_______________________________________________
Tutor maillist  -  Tutor at python.org
https://mail.python.org/mailman/listinfo/tutor

------------------------------

End of Tutor Digest, Vol 196, Issue 30
**************************************

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: data.txt
URL: <http://mail.python.org/pipermail/tutor/attachments/20200616/764a7529/attachment-0001.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Assign3_S11048116.py
URL: <http://mail.python.org/pipermail/tutor/attachments/20200616/764a7529/attachment-0001.ksh>
```