Due: December 1, 2025
Points: 100
In the given examples, what you type is in redand the program prints what is in black. The symbol ↵means a carriage return (return, enter).
Your program output should look like the output in the examples, except that what you type won’t be in red.
To access the PubMed database, go to the URL below, replacing keyword with the keyword you want to search for, and num the number of publications you would like returned:
https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&retmode=json&retmax=num&sort=relevance&term=keywordwith no spaces and all on a single line. So, for example, to find the 20 publications most relevant to “fever”, the URL would be:
https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&retmode=json&retmax=20&sort=relevance&term=feverwith no spaces and all on a single line.
When you read the contents of this web page, it is in the JSON format. You can turn this into a dictionary easily using the module json. The method json.loads(contents), where contents is the contents of the web page, returns a dictionary with one entry, the key of which is “esearchresults”. The associated value is another dictionary. The part you want is a list of the publication numbers. The key is “idlist” and the value is a list of the numbers.
You are to print the numbers of that list on a single line, with commas between them (no spaces). So, for the above, your output would look like this:
5822579,26772198,20660880,9208885,24176478,27209095,8698996,10913413,24176479,16895496,24176472,2200377,29940346,8272282,7567198,7432877,26514056,3056881,23160839,19578318but all on a single line. Note your numbers might differ from these because more relevant publications may be found.
Please prompt the user for the keyword to search for and the number of references. If the number of references entered is not a positive integer, give an error and quit.
Examples:
Enter a comma-separated list of keywords (no spaces!): covid How many references would you like (positive integers only): 7 33053381,33024307,35105985,35163638,33305456,33617700,34241776
Enter a comma-separated list of keywords (no spaces!): parkinson How many references would you like (positive integers only): 10 30890425,18344392,34034347,16361025,25611507,33237660,32273329,38844056,30149463,30573414
To turn in: Please call your program pubmed.py and submit it to Canvas
Hint: The URL begins with “https:”, so you will need to use the SSL stub in the sample programs (see geturl-ssl.py, for example).
We will do this in steps!
Be sure to check the input for validity. Specifically, the input must be a floating point number between 0 and 1 inclusive. If it is not a number, print “Invalid input; ” followed by the system error message. If it is a number but is not between 0 and 1, print “Probability must be between 0 and 1 inclusive”. In both cases, quit.
Examples:
Probability: 0.25
You need 15 people for two of them to have the same birthday with probability at least 0.25000
Probability: 0.7
You need 30 people for two of them to have the same birthday with probability at least 0.70000
Probability: 1.5
Probability must be between 0 and 1 inclusive
Probability: hello
Invalid input; could not convert string to float: ’hello’
To turn in: Please call your program pubmed.py and submit it to Canvas
Hint: Don’t be surprised if your numbers are slightly different than the ones shown in the sample output. As randomness is involved, it is possible your numbers will not match the ones shown here. Also, three versions of a function that returns True if a list has duplicates are available in the program hasdups.py, available on Canvas.
To turn in: Please call your program bday.py and submit it to Canvas
|
MHI 289I, Programming in Health Informatics Version of November 16, 2025 at 7:22PM
|
You can also obtain a PDF version of this. |