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...
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.
[4 marks] Write a Python program for a “Deliver-Eat!” app that asks the user for their...
[4 marks] Write a Python program for a “Deliver-Eat!” app that asks the user for their tip amount. If the user tips less than $5 they should receive a 1-star rating. If the user tips $5 or more they should receive a 5-star rating. Your program should match the output below. User input is in red. >>> How much would you like to tip? $4.50 >>> Here is your rating! * >>> How much would you like to tip? $7.20...
PYTHON: Write a program that asks the user to enter a 10-character telephone number in the...
PYTHON: Write a program that asks the user to enter a 10-character telephone number in the format XXX-XXX-XXXX. The application should display the telephone number with any alphabetic characters that appeared in the original translated to their numeric equivalent. For example, if the user enters 555-GET-FOOD, the application should display 555-438-3663. This is my code, but I cannot figure out where to go from here. #set new number new_number = "" #split number split_num = phone.split("-") for char in split_num[1:2]:...
Write a Python program that asks the user to enter a student's name and 8 numeric...
Write a Python program that asks the user to enter a student's name and 8 numeric tests scores (out of 100 for each test). The name will be a local variable. The program should display a letter grade for each score, and the average test score, along with the student's name. Write the following functions in the program: calc_average - this function should accept 8 test scores as arguments and return the average of the scores per student determine_grade -...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT