Question

In: Computer Science

USING PYTHON PROGRAM Part 4b: Addition Table Next, add in a feature that asks the user...

USING PYTHON PROGRAM

Part 4b: Addition Table

Next, add in a feature that asks the user if they want to identify 'Prime' numbers in their table. If the user elects to show prime numbers you can print a lowercase 'p' character after each prime number. Ensure that your table displays correctly, as described above.

Lowest number: 0
Highest number: 10
Would you like to identify Prime numbers in your table? (y/n): pikachu
Invalid command, try again
Would you like to identify Prime numbers in your table? (y/n): y
 +     0   1   2   3   4   5   6   7   8   9  10
------------------------------------------------
0  |   0   1  2p  3p   4  5p   6  7p   8   9  10
1  |   1  2p  3p   4  5p   6  7p   8   9  10 11p
2  |  2p  3p   4  5p   6  7p   8   9  10 11p  12
3  |  3p   4  5p   6  7p   8   9  10 11p  12 13p
4  |   4  5p   6  7p   8   9  10 11p  12 13p  14
5  |  5p   6  7p   8   9  10 11p  12 13p  14  15
6  |   6  7p   8   9  10 11p  12 13p  14  15  16
7  |  7p   8   9  10 11p  12 13p  14  15  16 17p
8  |   8   9  10 11p  12 13p  14  15  16 17p  18
9  |   9  10 11p  12 13p  14  15  16 17p  18 19p
10 |  10 11p  12 13p  14  15  16 17p  18 19p  20

Solutions

Expert Solution

Source COde:

def isPrime(n):
if(n<2):
return False
count=0
for i in range(2,n):
if(n%i==0):
count=count+1
break
if(count==0):
return True
else:
return False

lowest=int(input("Lowest number: "))
highest=int(input("Highest number: "))
choice=input("Would you like to identify Prime numbers in yout table?(y/n): ")
while (not(choice=='y')):
print("Invalid command,try again")
choice=input("Would you like to identify Prime numbers in yout table?(y/n): ")
  
print("+",end=" ")
for i in range(lowest,highest+1):
print(i,end=" ")

print()
print("-------------------------------------------------")
for i in range(lowest,highest+1):
print(i,"|",end=" ")
for j in range(lowest,highest+1):
if(isPrime(i+j)):
print((str(i+j)+'p'),end=" ")
else:
print(str(i+j),end=" ")
print()

Sample input and output:


Related Solutions

Write a program in PYTHON, using a while loop, that asks the user to enter the...
Write a program in PYTHON, using a while loop, that asks the user to enter the amount that they have budgeted for the month. The program should then prompt the user to enter their expenses for the month. The program should keep a running total. Once the user has finished entering their expenses the program should then display if the user is over or under budget. The output should display the monthly budget, the total expenses and whether the user...
Python: Write a program that asks the user for the name of a file. The program...
Python: Write a program that asks the user for the name of a file. The program should display the contents of the file line by line.
Using Python Write a program that does the following in order: 1.     Asks the user to enter...
Using Python Write a program that does the following in order: 1.     Asks the user to enter a name 2.     Asks the user to enter a number “gross income” 3.     Asks the user to enter a number “state tax rate” 4.     Calculates the “Federal Tax”, “FICA tax” and “State tax” 5.     Calculates the “estimated tax” and round the value to 2 decimal places 6.     Prints values for “name”, “gross income” and “estimated tax” The program should contain three additional variables to store the Federal tax, FICA...
In Python write a program that asks the user to enter the monthly costs for the...
In Python write a program that asks the user to enter the monthly costs for the following expenses incurred from operating his or her automobile: loan payment, insurance, gas, oil, tires, and maintenance the program should then display the total monthly cost of these expenses, and the total annual cost of these expenses. your program MUST have BOTH a main function AND a function named calcExpenses to calculate the expenses. DO NOT display the expenses inside of the calcExpenses function!!...
Write a design algorithm and a python program which asks the user for the length of...
Write a design algorithm and a python program which asks the user for the length of the three sides of two triangles. It should compute the perimeter of the two triangles and display it. It should also display which triangle has the greater perimeter. If both have the same perimeter it should display that the perimeters are the same. Formula: Perimeter of triangleA = (side1A + side2A +side3A) See the 2 sample outputs. Enter side1 of TriangleA: 2 Enter side2...
Python English algorithm explanation Write a program that asks the user for the name of a...
Python English algorithm explanation Write a program that asks the user for the name of a file in the current directory. Then, open the file and process the content of the file. 1)If the file contains words that appear more than once, print “We found duplicates.” 2)If the file does not contain duplicate words, print “There are no duplicates.”
Python English algorithm explanation Write a program that asks the user for the name of a...
Python English algorithm explanation Write a program that asks the user for the name of a file in the current directory. Then, open the file and process the content of the file. 1)If the file contains words that appear more than once, print “We found duplicates.” 2)If the file does not contain duplicate words, print “There are no duplicates.”
Write a complete Python program that asks the user for a line of text (not just...
Write a complete Python program that asks the user for a line of text (not just a single word), and then tells the user whether the string is a palindrome (same forward and backward) if you ignore case and non-alphabetic characters. The following methods and functions may be useful: str.upper(), str.isalpha() -> bool, reversed(str) -> sequence, str.find(str) -> int, str.replace(str, str), str.center(int). Unless otherwise specified, they all return a string.
CODE IN PYTHON 1. Write a program that asks the user for the number of slices...
CODE IN PYTHON 1. Write a program that asks the user for the number of slices of pizza they want to order and displays the total number of dollar bills they owe given pizza costs 3 dollars a slice.  Note: You may print the value an integer value. 2. Assume that y, a and b have already been defined, display the value of x: x =   ya+b    3. The variable start_tees refers to the number of UD T-shirts at the start...
(IN PYTHON) Write a program that asks the user repeatedly to enter a student's score or...
(IN PYTHON) Write a program that asks the user repeatedly to enter a student's score or enter -1 to stop. When finished entering all the scores, the program should display the number of scores entered, the sum of the scores, the mean, the lowest and the highest score. (IN PYTHON)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT