You are on page 1of 22

PE Sample PRP201c Fall 2021

Đề 1 :

1. (3 points) A prime number is the number that has only two factors: 1 and the
number itself. For example, 2, 3, 5, 7 and 11 are the first few prime numbers. Write a
program that repeatedly prompts a user for numbers until the user enters a positive
interger number. Once a valid number is entered, print out the list of prime number
from 0 to the entered number. If the user enters anything other than a valid number
catch it with a try/except and put out an appropriate message and ignore the number.
For example, enter -1, bob and 10 and match the output below.
Enter a positive integer number: -1
The number must be positive.
Enter a positive integer number: bob
The number must be a positive number.
Enter a positive integer number: 10
The prime numbers from 0 to 10:
2357
2. (3 points) Write a program to read through the file “Trace.txt” and figure out the
distribution by name of the providers. You can pull the name out from the 'Name ' line
and then splitting the string.
Name: Microsoft-Windows-L2NACP
Once you have accumulated the counts for each name, print out the counts, sorted by
name.
For example, enter a file name “Trace.txt” or leave it blank and match the output
below.
Enter file:Trace.txt
Troubleshoot wired LAN related issues:
Apple: 2
Microsoft: 3

3. (4 points) Write a program to read the the file “Trace.txt” and count the number of
troubles per organization and then save data to the database file Trace.sqlite using a
database with the following schema to maintain the counts.

CREATE TABLE Providers (Pname TEXT, Pcount INTEGER, Pwarning TEXT)


If the number of troubles per organization > 1, write "high risk" to Pwarning column.
Otherwise, write " Normal" to Pwarning column.
The program prints all rows of the table when sorted in descending order by Pcount.
The output should be as follows:
Troubleshoot wired LAN related issues:
provider Count Warning
Microsoft 5 high risk
Apple 3 high risk
Google 2 high risk
IBM 1 Normal
Đề 2 :
Đề 3 :

You might also like