From tobywobycarlton at icloud.com Mon Mar 1 17:05:23 2021 From: tobywobycarlton at icloud.com (Toby Carlton) Date: Mon, 1 Mar 2021 15:05:23 -0700 Subject: [Tutor] Python Quit Unexpectedly Message-ID: <09873E64-ED3D-4415-99D6-75697EAD0872@icloud.com> Every time I try to run pygame.display.set_mode() it gives me the error message - python quit unexpectedly. Please help! From alan.gauld at yahoo.co.uk Tue Mar 2 17:06:26 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Tue, 2 Mar 2021 22:06:26 +0000 Subject: [Tutor] Python Quit Unexpectedly In-Reply-To: <09873E64-ED3D-4415-99D6-75697EAD0872@icloud.com> References: <09873E64-ED3D-4415-99D6-75697EAD0872@icloud.com> Message-ID: On 01/03/2021 22:05, Toby Carlton via Tutor wrote: > Every time I try to run pygame.display.set_mode() it gives me the error message - python quit unexpectedly. Please help! Can you provide the basic context please: Which OS are you using? Which Python version? How are you erunning the code? And can you include at least the function that calls pygame.display.set_mode()? Better yet the full file if its not hundreds of lines long. -- 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 From torbjorn.svensson.diaz at gmail.com Fri Mar 5 08:50:22 2021 From: torbjorn.svensson.diaz at gmail.com (=?UTF-8?Q?Torbj=c3=b6rn_Svensson_Diaz?=) Date: Fri, 5 Mar 2021 14:50:22 +0100 Subject: [Tutor] Minimum Skill Set Message-ID: Hello, tutors! I have a question about computer programming. Some programmers have PhD degrees, a full third of US programmers have no degrees and three quarters of US programming jobs don't require degrees. So what is the minimum skill set needed to perform the easiest programming tasks for a programmer or software tester? At https://teachyourselfcs.com/ material that all programmers should master are listed. OTOH, there seems to be a lot of programmer that make a living out of programming or software testing mastering less material. What is the absolute minimum? Best regards, -- Torbj?rn Svensson Diaz From alan.gauld at yahoo.co.uk Fri Mar 5 14:27:27 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Fri, 5 Mar 2021 19:27:27 +0000 Subject: [Tutor] Minimum Skill Set In-Reply-To: References: Message-ID: On 05/03/2021 13:50, Torbj?rn Svensson Diaz wrote: > I have a question about computer programming. Some programmers have PhD > degrees, a full third of US programmers have no degrees and three > quarters of US programming jobs don't require degrees. So what is the > minimum skill set needed to perform the easiest programming tasks for a > programmer or software tester? The answer to this varies quite a bit and depends on what you mean by "programmer". The British Computer Society has a grading system for IT jobs (the Industry Standard Model or ISM) and it defines programmer as a relatively low skilled (and low paid) job similar to say an office clerk or newly qualified tradesman or almost qualified apprentice. By that they mean someone who writes code that somebody else has designed down to procedure or function level. They may have a high school qualification in computing or have done an IT apprenticeship. Below that there are those who are not officially programmers but who spend a lot of time writing code. This includes system administrators etc (When I say 'below' I do not mean admins are lower rated than programmers, quite the opposite! Rather I mean in the sense of formal programming skills and training.) Next up the ratings comes the systems programmer/analyst. These usually have a formal qualification in programming and can create program designs (ie for a single process). They can take in business requirements and translate them to software designs. These folks earn around the same as a fully qualified and experienced tradesman such as a plumber or electrician. Software testers sit in this area too. Then comes software engineers. These are folks who can design large scale systems with multiple processes and complex data models. Often involving networking etc. This is what the general public often think of when they think "Programmer" They will usually have a degree of some kind(not necessarily CS) And they earn similar money to other professionals such as civil engineers, etc. Software engineers tend to spend a minority of their time actually writing code(say 20-40%). Getting near the top we have architects who define high level system structures, determine corporate IT strategy and design the very largest systems. They often have post graduate qualifications and many years experience. They earn mid-upper management salaries (notice the significant shift in comparison from engineer to manager!) Architects typically spend very little time (<10%) writing code, but they may spend a lot of time reading other peoples(~20%)! And that's the UK view, and I think similar to much of Europe. But the approaches in other areas of the world are quite different! Also, even in the UK it is a somewhat outdated view and may even have been updated recently (I ended my involvement with BCS back about 2005) The model I decribed was based largely on the old Mainframe computing, corporate IT department mentality. In practice, the layers described above still apply but the lower ones now include folks working on web sites with very little formal training, having started on HTML/CSS and copying snippets of Javascript. They have built their skills but probably have little if any CS training. The absolute minimum is: however little you can persuade someone to employ you! I know of one guy with zero formal training who is called a programmer in his job title but still only writes HTML/CSS and copies snippets of Javascript or asks questions on stack-exchange and copies the answers into his code, without knowing how they work. But if you don't want to spend your life (re)writing web front ends for basic level web sites and have aspirations to develop full stack applications or work on large systems, or use state of the art practices you will likely want a qualification behind you. It doesn't need to be a CS degree. Any form of STEM course will usually suffice to get you into a job. After that its more about what you do and the experience you acquire. And remember those pay ranges. Being a "programmer" is no guarantee of high pay. You could be earning the same as a new qualified hairdresser (without tips) or on a 6 figure salary. There is a world of difference out there. Finally, there is another category of programmer who is a specialist in some field or other. They may spend their whole life working on a single piece of code. Or they write highly complex code related to a specialist topic like astrophysics or weather simulations. These folks can be earning big money but working like the tier two guy. And often qualified at PhD level - but in their specialism not in "programming". And, as I say, things work very differently in other places. The only areas I have any experience with are the USA and India. But I'll let others with more direct experience comment. -- 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 From Steve.Flynn at capita.com Fri Mar 5 14:06:58 2021 From: Steve.Flynn at capita.com (Flynn, Stephen (Life & Pensions)) Date: Fri, 5 Mar 2021 19:06:58 +0000 Subject: [Tutor] Minimum Skill Set In-Reply-To: References: Message-ID: Absolute minimum - the ability to read and think. S. -----Original Message----- From: Tutor On Behalf Of Torbj?rn Svensson Diaz Sent: Friday, March 5, 2021 1:50 PM To: tutor at python.org Subject: [Tutor] Minimum Skill Set **EXTERNAL** Hello, tutors! I have a question about computer programming. Some programmers have PhD degrees, a full third of US programmers have no degrees and three quarters of US programming jobs don't require degrees. So what is the minimum skill set needed to perform the easiest programming tasks for a programmer or software tester? At https://teachyourselfcs.com/ material that all programmers should master are listed. OTOH, there seems to be a lot of programmer that make a living out of programming or software testing mastering less material. What is the absolute minimum? Best regards, -- Torbj?rn Svensson Diaz _______________________________________________ Tutor maillist - Tutor at python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor This message has been scanned by Capita systems, but if you believe it to be spam, please send it to spam at forcepoint.com. Messages sent to spam at forcepoint.com are queued for email analysis by Forcepoint Threat Lab. This email originates from outside of Capita. Keep this in mind before responding, opening attachments or clicking any links. Unless you recognise the sender and know the content is safe. If in any doubt, the grammar and spelling are poor, or the name doesn't match the email address then please contact the sender via an alternate known method. This email is security checked and subject to the disclaimer on web-page: https://www.capita.com/email-disclaimer.aspx From sjeik_appie at hotmail.com Thu Mar 11 09:37:33 2021 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Thu, 11 Mar 2021 15:37:33 +0100 Subject: [Tutor] About (dev-)requirements.txt Message-ID: Hi, How do I generate separate (i.e., disjoint) lists of requirements for the app itself and the dev-requirements? I know I can use pip freeze, but how do I separate dev and non-dev? Let's say I use nose, pdoc3 and tox for dev-requirements.txt. How do I separate those packages AND their dependencies from the non-dev requirements.txt? And what do I do with libraries like setuptools, wheel and pip? Should they be in both lists? Or should they be installed first, before anything else? I recently experienced many problems related to old pip/wheel versions after I tried to recreate a virtualenv with existing requirement.txt's but a higher Python version so I hope next time this process will be less "trial and error". Thanks! Albert-Jan From PyTutor at DancesWithMice.info Thu Mar 11 15:01:38 2021 From: PyTutor at DancesWithMice.info (dn) Date: Fri, 12 Mar 2021 09:01:38 +1300 Subject: [Tutor] About (dev-)requirements.txt In-Reply-To: References: Message-ID: <90e3ea5c-cd0d-5c92-8a97-9471e833bc2f@DancesWithMice.info> On 12/03/2021 03.37, Albert-Jan Roskam wrote: > Hi, > How do I generate separate (i.e., disjoint) lists of requirements for the > app itself and the dev-requirements? I know I can use pip freeze, but how > do I separate dev and non-dev? Let's say I use nose, pdoc3 and tox for > dev-requirements.txt. How do I separate those packages AND their > dependencies from the non-dev requirements.txt? > And what do I do with libraries like setuptools, wheel and pip? Should > they be in both lists? Or should they be installed first, before anything > else? I recently experienced many problems related to old pip/wheel > versions after I tried to recreate a virtualenv with existing > requirement.txt's but a higher Python version so I hope next time this > process will be less "trial and error". This is an interesting question: there are a number of methodologies which aim to ensure that whatever was needed in the dev.env, 'everything' is carried-forward into "prod". However, there are indeed some things we don't (necessarily) want! Perhaps an opposite view is to ask: why bother? What does it matter if some test or debug tool is replicated in "prod". It should never be used/called. Is the storage-space it occupies, significant? Thus, is it worth the brain-time? Rather than listing the components of the environment, which tool are you using to parcel-up the code and deliver it/replicate it? -- Regards, =dn From mats at wichmann.us Thu Mar 11 15:32:39 2021 From: mats at wichmann.us (Mats Wichmann) Date: Thu, 11 Mar 2021 13:32:39 -0700 Subject: [Tutor] About (dev-)requirements.txt In-Reply-To: References: Message-ID: <08abe77c-51a0-56e8-d482-622429807d11@wichmann.us> On 3/11/21 7:37 AM, Albert-Jan Roskam wrote: > Hi, > How do I generate separate (i.e., disjoint) lists of requirements for the > app itself and the dev-requirements? I know I can use pip freeze, but how > do I separate dev and non-dev? Let's say I use nose, pdoc3 and tox for > dev-requirements.txt. How do I separate those packages AND their > dependencies from the non-dev requirements.txt? > And what do I do with libraries like setuptools, wheel and pip? Should > they be in both lists? Or should they be installed first, before anything > else? I recently experienced many problems related to old pip/wheel > versions after I tried to recreate a virtualenv with existing > requirement.txt's but a higher Python version so I hope next time this > process will be less "trial and error". > Thanks! > Albert-Jan This seems to be a space where conventions are evolving. I used to hear the advice to put install requirements in setup.py, and build requirements in requirements.txt. More recently I've heard people using separate requirements files, like you mention. requirements-dev.txt seems to be the convention - PyPi even has a dummy package of this name to prevent issues if you try to install using this file and leave out the "-r". https://pypi.org/project/requirements-dev.txt/ If you're using pipenv (I don't, at the moment, so this is just from reading docs, not personal experience): pipenv lock -r and pipenv lock -r --dev will generate you separate lists for runtime and for dev. BUT... that means you already had to record what you wanted in the pipfile, so it feels kind of like "to solve the problem, you first have to solve the problem" :) Let us know what you find out... From alan.gauld at yahoo.co.uk Thu Mar 11 16:30:54 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Thu, 11 Mar 2021 21:30:54 +0000 Subject: [Tutor] About (dev-)requirements.txt In-Reply-To: References: Message-ID: On 11/03/2021 14:37, Albert-Jan Roskam wrote: > How do I generate separate (i.e., disjoint) lists of requirements for the > app itself and the dev-requirements? Ok, This one puzzles me. I come from a background of large projects, with typically between 50-500 developers. Requirements are something catalogued in a book (possibly several volumes - the biggest I saw was 7 volumes of 50-100+ ages each) or in a CASE tool (eg Borland Together) or a project management tool such as Jira. I would expect a total of several thousand requirements, with each release addressing perhaps 100-200 at a time. But these requirements would be business requirements: Like: Req010301: The system should calculate customer propensity to spend using the McClelland-Smythe algorithm (version 2) or R-Sales-003: The sales agent shall be presented with a list of up-selling and cross-selling opportunities based on both current promotions and the customers previous sales history. Or, most commonly, a use case scenario which would encompass several linked requirements. Are these the kinds of application requirements you have in mind? And I'm not sure what you mean by dev-requirements? Are these perhaps the low level developer user stories we had to create as part of system design? Things like: I want the up-selling and cross-selling product lists to appear in a single panel on the Sales screen so that I do not lose sight of the current customer data. Or is it something else? Can you give examples of both type of requirements? -- 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 From mats at wichmann.us Thu Mar 11 19:28:22 2021 From: mats at wichmann.us (Mats Wichmann) Date: Thu, 11 Mar 2021 17:28:22 -0700 Subject: [Tutor] About (dev-)requirements.txt In-Reply-To: References: Message-ID: On 3/11/21 2:30 PM, Alan Gauld via Tutor wrote: > On 11/03/2021 14:37, Albert-Jan Roskam wrote: >> How do I generate separate (i.e., disjoint) lists of requirements for the >> app itself and the dev-requirements? > > Ok, This one puzzles me. > I come from a background of large projects, with typically > between 50-500 developers. Requirements are something catalogued > in a book Requirements is the wrong word, but that seems to be the term the Python packaging ecosystem settled on. It's "dependencies", as in other Python packages needed... It's a problem that's very actual for me, as I'm working on a project that can be run with nothing but the Python standard library, but for a project developer, there are dependencies - xml tools, sphinx documentation generator, etc. - these are development dependencies, but not runtime dependencies, and we've also wrestled with keeping them straight. From sjeik_appie at hotmail.com Fri Mar 12 03:31:14 2021 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Fri, 12 Mar 2021 09:31:14 +0100 Subject: [Tutor] About (dev-)requirements.txt In-Reply-To: Message-ID: On 12 Mar 2021 01:28, Mats Wichmann wrote: On 3/11/21 2:30 PM, Alan Gauld via Tutor wrote: > On 11/03/2021 14:37, Albert-Jan Roskam wrote: >> How do I generate separate (i.e., disjoint) lists of requirements for the >> app itself and the dev-requirements? > > Ok, This one puzzles me. > I come from a background of large projects, with typically > between 50-500 developers. Requirements are something catalogued > in a book =====>> Hi all, @Alan: this is a nice page about it https://blog.usejournal.com/why-and-how-to-make-a-requirements-txt-f329c685181e I've read a bit more about this and I *may* have a solution (I haven't tried it yet). It assumes a virtualenv is used. Let's say I use pandas in my project and pandas itself has two dependencies, numpy and openpyxl. pip freeze > constraints.txt now move the *direct* dependencies (i.e. pandas) of the project in a file requirements.txt so i looks like: -c constraints.txt pandas==1.0.0 Constraints.txt looks like: numpy==1.0.0 openpyxl==1.0.0 Installation is simply pip install -r requirements.txt *If* any of the direct requirements need something in constraints.txt, they are constrained to the given version. Separating the "real" (=direct) requirements into dev and non-dev is now relatively easy. Although I also like DN's answer: why worry about it? Best wishes, Albert-Jan From sjeik_appie at hotmail.com Fri Mar 12 11:32:04 2021 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Fri, 12 Mar 2021 17:32:04 +0100 Subject: [Tutor] About (dev-)requirements.txt In-Reply-To: Message-ID: =====>> Hi all, Ps: I should have added the source: https://luminousmen.medium.com/pip-constraints-files-b684992705b6 From alan.gauld at yahoo.co.uk Sun Mar 14 08:19:32 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Sun, 14 Mar 2021 12:19:32 +0000 Subject: [Tutor] About (dev-)requirements.txt In-Reply-To: References: Message-ID: On 12/03/2021 00:28, Mats Wichmann wrote: > On 3/11/21 2:30 PM, Alan Gauld via Tutor wrote: >> On 11/03/2021 14:37, Albert-Jan Roskam wrote: >>> How do I generate separate (i.e., disjoint) lists of requirements for the >>> app itself and the dev-requirements? >> >> Ok, This one puzzles me. >> I come from a background of large projects, with typically >> between 50-500 developers. Requirements are something catalogued >> in a book > > Requirements is the wrong word, but that seems to be the term the Python > packaging ecosystem settled on. It's "dependencies", as in other Python > packages needed... Thanks for the clarification. Unfortunately that means I have nothing to contribute, I steer clear of that whole packaging thing as much as possible! :-) -- 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 From singh000taran at gmail.com Sun Mar 14 07:53:32 2021 From: singh000taran at gmail.com (=?UTF-8?B?4Kmn?=) Date: Sun, 14 Mar 2021 17:23:32 +0530 Subject: [Tutor] (no subject) Message-ID: Respected sir, please guide me with the question given below. I don't fully understand the question. Write a python program to read from input a string. The input contains COMMA separated string values. The output of the program is the count of string values where (a) the length is >= 2; AND (b) the first and last character of the string value are the same. Input: abc,xyz,aba,1221,1 Output: 2 Input: abc, xyz , alpha Output: 1 [Note that the second string ( xyz ) has SPACE at the start and at the end; while the last string ( alpha) has SPACE only at the start. From singh000taran at gmail.com Sun Mar 14 08:39:58 2021 From: singh000taran at gmail.com (=?UTF-8?B?4Kmn?=) Date: Sun, 14 Mar 2021 18:09:58 +0530 Subject: [Tutor] (no subject) Message-ID: Dear sir, I have not studies graph-related things in python. While answering please try to be more descriptive; I will be grateful if you do so. Question - In this problem, you need to create a program for managing Graphs. The input to the program will be as described next: The first line will contain a positive integer NN. NN denotes the number of nodes in the graph. Nodes themselves are numbered from 0 to N?1N?1. The second line will contain a non-negative integer MM (M?0M?0). This will be the number of edges in the graph (However, some of these could be invalid/duplicate). The next MM lines each will contain a pair of integers i,ji,j representing a directed edge i?ji?j. Self edges (i?ii?i) are allowed. However, multi-edges (two or more instances of i?ji?j) have to be stored only once. Last line will contain an integer kk. The output of the program is: If kk represents a valid node, print all the nodes ss such that s?ks?k is a (directed) edge in the graph. The nodes have to be in sorted order, separated by COMMA (no whitespace). If kk does not represent a valid node, print "ERROR: Invalid Node." EXAMPLES ___________________________________ INPUT: 3 4 0,1 1,2 2,0 0,2 2 OUTPUT: 0,1 _____________________________ INPUT: 3 4 0,1 0,2 2,0 0,2 2 OUTPUT: 0 _____________________________ INPUT: 1 0 0 OUTPUT: (Note empty output) _____________________________ NOTE: Remember that Self edges (i?ii?i) are allowed. Multi-edges (two or more instances of i?ji?j) have to be counted only once. From singh000taran at gmail.com Sun Mar 14 08:52:36 2021 From: singh000taran at gmail.com (=?UTF-8?B?4Kmn?=) Date: Sun, 14 Mar 2021 18:22:36 +0530 Subject: [Tutor] (no subject) In-Reply-To: References: Message-ID: I am writing the question again in a more readable form. Write a python program to read from input a string. The input contains COMMA separated string values. The output of the program is the count of string values where (a) the length is >= 2; AND (b) the first and last character of the string value are the same. Input: abc,xyz,aba,1221,1 Output: 2 Input: abc, xyz , alpha Output: 1 [Note that the second string ( xyz ) has SPACE at the start and at the end; while the last string ( alpha) has SPACE only at the start. On Sun, Mar 14, 2021 at 5:52 PM ? wrote: > Respected sir, please guide me with the question given below. I don't fully > understand the question. > Write a python program to read from input a string. The input contains > COMMA separated string values. The output of the program is the count of > string values where (a) the length is >= 2; AND (b) the first and last > character of the string value are the same. Input: abc,xyz,aba,1221,1 > Output: 2 Input: abc, xyz , alpha Output: 1 [Note that the second string ( > xyz ) has SPACE at the start and at the end; while the last string ( alpha) > has SPACE only at the start. > _______________________________________________ > Tutor maillist - Tutor at python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > -- TaranSingh From alan.gauld at yahoo.co.uk Sun Mar 14 10:46:40 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Sun, 14 Mar 2021 14:46:40 +0000 Subject: [Tutor] (no subject) In-Reply-To: References: Message-ID: On 14/03/2021 11:53, ? wrote: > Respected sir, please guide me with the question given below. I don't fully > understand the question. What parts do you not understand? What parts do you understand? > Write a python program to read from input a string. Do you know how to do that? Consider the input() function. > The input contains COMMA separated string values. Do you know how to separate a string into separate fields? Consider the string.split() method. > The output of the program is the count of > string values where (a) the length is >= 2; Do you know how to find the length of a string Consider the len() function Do you know how to increment a counter for a condition? Consider the if construct and addition operator AND (b) the first and last > character of the string value are the same. Do you know how to extract the first and last characters of a string? Consider indexing Do you know how to logically combine tests (with AND in this case?) Consider the boolean operators. > Input: abc,xyz,aba,1221,1 > Output: 2 Do you understand why the output is 2? Can you write code that produces that result? Input: abc, xyz , alpha Output: 1 [Note that the second string ( > xyz ) has SPACE at the start and at the end; while the last string ( alpha) > has SPACE only at the start. Including spaces as part of the fields is sneaky but does not, in practice, make things any more easy or difficult. Note that we do not do homework for you, but we will review your code and offer suggestions(as above0 to help you do your homework. -- 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 From learn2program at gmail.com Mon Mar 15 19:56:15 2021 From: learn2program at gmail.com (Alan Gauld) Date: Mon, 15 Mar 2021 23:56:15 +0000 Subject: [Tutor] Fwd: Graph question was: Re: (no subject) In-Reply-To: References: Message-ID: <97959d16-764a-f64e-051c-fceeb44539a3@gmail.com> Forwarding to the group.... -------- Forwarded Message -------- I have written it in a more readable format. In this problem, you need to create a program for managing Graphs. The input to the program will be as described next: The first line will contain a positive integer NN. NNdenotes the number of nodes in the graph. Nodes themselves are numbered from 0 to N?1N?1. ?The second line will contain a non-negative integer MM(M?0M?0). This will be the number of edges in the graph (However, some of these could be invalid/duplicate). The next MMlines each will contain a pair of integers i,ji,jrepresenting a directed edge i?ji?j. Self edges (i?ii?i) are allowed. However, multi-edges (two or more instances of i?ji?j) have to be stored only once. Last line will contain an integer kk. The output of the program is: If kkrepresents a valid node, print all the nodes sssuch that s?ks?kis a (directed) edge in the graph. The nodes have to be in sorted order, separated by COMMA (no whitespace). If kkdoes not represent a valid node, print "ERROR: Invalid Node." EXAMPLES ___________________________________ INPUT: 3 4 0,1 1,2 2,0 0,2 2 OUTPUT: 0,1 _____________________________ INPUT: 3 4 0,1 0,2 2,0 0,2 2 OUTPUT: 0 _____________________________ INPUT: 1 0 0 OUTPUT: (Note empty output) _____________________________ NOTE: Remember that Self edges (i?ii?i) are allowed. Multi-edges (two or more instances of i?ji?j) have to be counted only once. On Sun, Mar 14, 2021 at 8:28 PM Alan Gauld > wrote: Please supply a relevant subject line, it makes tracking the discussion much easier. On 14/03/2021 12:39, ? wrote: > Dear sir, I have not studies graph-related things in python. Have you studied graphs in math? Python is pretty much irrelevant since it does not directly deal in graphs. You need to do that yourself. ie. can you solve the problem below without Python? If not then that is where you must start. First understand the problem. > The first line > will contain a positive integer NN. NN denotes the number of nodes in the > graph. Nodes themselves are numbered from 0 to N?1N?1. OK, This has lost me already. The number of nodes should surely be N? Not NN? How are the nodes in a graph numbered Can you provide an example? The input samples below do not appear to match the description. Can you repost the question with clearer formatting and better examples? The more you can help us the more we can help you. > The second line will > contain a non-negative integer MM (M?0M?0). This will be the number of > edges in the graph (However, some of these could be invalid/duplicate). The > next MM lines each will contain a pair of integers i,ji,j representing a > directed edge i?ji?j. Self edges (i?ii?i) are allowed. However, multi-edges > (two or more instances of i?ji?j) have to be stored only once. Last line > will contain an integer kk. The output of the program is: If kk represents > a valid node, print all the nodes ss such that s?ks?k is a (directed) edge > in the graph. The nodes have to be in sorted order, separated by COMMA (no > whitespace). If kk does not represent a valid node, print "ERROR: Invalid > Node." EXAMPLES ___________________________________ INPUT: 3 4 0,1 1,2 2,0 > 0,2 2 OUTPUT: 0,1 _____________________________ INPUT: 3 4 0,1 0,2 2,0 0,2 > 2 OUTPUT: 0 _____________________________ INPUT: 1 0 0 OUTPUT: (Note empty > output) _____________________________ NOTE: Remember that Self edges (i?ii?i) > are allowed. Multi-edges (two or more instances of i?ji?j) have to be > counted only once. -- 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 -- TaranSingh From alan.gauld at yahoo.co.uk Mon Mar 15 20:34:34 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Tue, 16 Mar 2021 00:34:34 +0000 Subject: [Tutor] Fwd: Graph question was: Re: (no subject) In-Reply-To: <97959d16-764a-f64e-051c-fceeb44539a3@gmail.com> References: <97959d16-764a-f64e-051c-fceeb44539a3@gmail.com> Message-ID: On 15/03/2021 23:56, Alan Gauld wrote: > I have written it in a more readable format. > In this problem, you need to create a program for managing Graphs. The > input to the program will be as described next: The first line will > contain a positive integer NN. NNdenotes the number of nodes in the > graph. Nodes themselves are numbered from 0 to N?1N?1. I'm probably just being dense but I still don't understand this. It says the number is NN which denotes the number of nodes. I'd read that as a two digit number. Then it says it ranges from 0 to N-1 That suggests to me that the number of nodes should really read the index of the highest node? Maybe? Except... It says "numbered from 0 to N-1N-1" which suggests that if N is, say, 5 the numbering could be up to 44? Which makes no sense to me at all! > ?The second line will contain a non-negative integer MM(M?0M?0). This > will be the number of edges in the graph (However, some of these could > be invalid/duplicate). This has a similar issue in that how is a single number of edges represented using a double digit? And when we look at the sample data below the first two "lines" are both single digits... > The next MMlines each will contain a pair of > integers i,ji,jrepresenting a directed edge i?ji?j. Self edges (i?ii?i) > are allowed. However, multi-edges (two or more instances of i?ji?j) have > to be stored only once. Last line will contain an integer kk. And what is kk supposed to be? There is no explanation. > If kkrepresents a valid node, print all the nodes > sssuch that s?ks?kis a (directed) edge in the graph. OK, Now we have a sort of explanation for kk - it might be a node. but we introduce a new term s. What is s? > ___________________________________ INPUT: 3 4 0,1 1,2 2,0 0,2 2 OUTPUT: > 0,1 I assume this should be written: 3 4 0,1 1,2 2,0 0,2 2 ie 3 nodes, 4 edges and the mystery node is 2. The solution is apparently 0,1 but I'm not sure why? As I say, it's probably me missing something (and my graph theory days are long behind me so that's very likely!) But unless we understand what the data represents and how the output should be calculated we can't begin to discuss what the Python code might look like. -- 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 From PyTutor at DancesWithMice.info Mon Mar 15 20:52:57 2021 From: PyTutor at DancesWithMice.info (dn) Date: Tue, 16 Mar 2021 13:52:57 +1300 Subject: [Tutor] Fwd: Graph question was: Re: (no subject) In-Reply-To: References: <97959d16-764a-f64e-051c-fceeb44539a3@gmail.com> Message-ID: <4ed3cb44-7f51-4faf-c614-29175042b791@DancesWithMice.info> On 16/03/2021 13.34, Alan Gauld via Tutor wrote: > On 15/03/2021 23:56, Alan Gauld wrote: > >> I have written it in a more readable format. >> In this problem, you need to create a program for managing Graphs. The >> input to the program will be as described next: The first line will >> contain a positive integer NN. NNdenotes the number of nodes in the >> graph. Nodes themselves are numbered from 0 to N?1N?1. > > I'm probably just being dense but I still don't understand this. > > It says the number is NN which denotes the number of nodes. > I'd read that as a two digit number. > > Then it says it ranges from 0 to N-1 > That suggests to me that the number of nodes should really > read the index of the highest node? Maybe? Except... > > It says "numbered from 0 to N-1N-1" which suggests that if > N is, say, 5 the numbering could be up to 44? > Which makes no sense to me at all! > >> ?The second line will contain a non-negative integer MM(M?0M?0). This >> will be the number of edges in the graph (However, some of these could >> be invalid/duplicate). > > This has a similar issue in that how is a single number of edges > represented using a double digit? > > And when we look at the sample data below the first > two "lines" are both single digits... > >> The next MMlines each will contain a pair of >> integers i,ji,jrepresenting a directed edge i?ji?j. Self edges (i?ii?i) >> are allowed. However, multi-edges (two or more instances of i?ji?j) have >> to be stored only once. Last line will contain an integer kk. > > And what is kk supposed to be? There is no explanation. > >> If kkrepresents a valid node, print all the nodes >> sssuch that s?ks?kis a (directed) edge in the graph. > > OK, Now we have a sort of explanation for kk - it might be a node. > but we introduce a new term s. What is s? > >> ___________________________________ INPUT: 3 4 0,1 1,2 2,0 0,2 2 OUTPUT: >> 0,1 > > I assume this should be written: > > 3 > 4 > 0,1 > 1,2 > 2,0 > 0,2 > 2 > > ie 3 nodes, 4 edges and the mystery node is 2. > The solution is apparently 0,1 but I'm not sure why? > > As I say, it's probably me missing something (and my > graph theory days are long behind me so that's very > likely!) > > But unless we understand what the data represents > and how the output should be calculated we can't > begin to discuss what the Python code might look > like. +1 The first confusion, eg "NN", is likely caused by a failed transition from the original format of the assignment into email. It makes sense when one ignores the duplication, instead reading "N" or "N?1"... Your re-formatting of the graph-data makes tremendous sense - because it is so much easier to read! It is a case where I'd be recommending the use of JSON/YAML (even XML) to avoid errors through self-documentation, eg nodes_count: 3 edges_count: 4 edge: 0,1 ... NB don't quote me - I can't remember the exact purposes of each of those numbers. Also, I fail to see why the second is necessary if there are that number of pairs of edge information. As you say, what are we missing? Sadly, there are still tutors who seem to feel that assignments should hinge on understanding arcane aspects, instead of testing the trainee's understanding of Python and/or Graph Theory. My sympathy to the students... As it happens, I've just dusted-off my Graph Theory as part of evaluating AWS' Neptune (graph database). So, IMHO the assignment does make sense. Although the trivial nature and paucity of sample-data is not unduly helpful (perhaps less critical if the course is in Graph Theory cf Python Coding!). (I think) I can see what is required. Hence the earlier response asking the OP for his progress and ideas towards solution... -- Regards, =dn From sb.monzur at gmail.com Wed Mar 17 01:15:22 2021 From: sb.monzur at gmail.com (S Monzur) Date: Wed, 17 Mar 2021 11:15:22 +0600 Subject: [Tutor] How to write a loop in python to find HTML tags in a text file Message-ID: Dear all, The attached text file contains data from 3 news articles scraped from a news website. I would like to write a loop that separates the metadata from the article body for each of these three articles. The linked code works for a single news article only (i.e., if I keep only one article in the text file). People have previously suggested using beautiful soup and regular expressions, but please note that I just want to modify the existing code to add a loop, and not use any other methods/functions. Note about the text file: 1. H1 class tag denotes the start of each article. The tag div class=