import math
def parity(num):
if num%2 == 0:
return "Even"
else:
return "Odd"
def palindrome(num):
n=num
temp=n
rev=0
while(n>0):
dig=n%10
rev=rev*10+dig
n=n//10
if(temp==rev):
return "True"
else:
return "False"
def perfect_cube(num):
cube_root = num**(1./3.)
if round(cube_root) ** 3 == num:
return "True"
else:
return "False"
def perfect_square(num):
i = int(math.sqrt(num))
if(num == i*i):
return "True"
else:
return "False"
def prime(num):
if num > 1:
for i in range(2,num):
if (num % i) == 0:
return "False"
break
else:
return "True"
else:
return "False"
def perfect(num):
Sum = 0
for i in range(1, num):
if(num % i == 0):
Sum = Sum + i
if (Sum == num):
return "True"
else:
return "False"
num=(input("enter number"))
if '.' in num:
num=float(num)
elif ',' in num:
print("Error! Invalid input for a natural number")
exit()
else:
num=int(num)
if isinstance(num,(int,float)):
if (num)>0:
if isinstance(num,int):
parity=parity(num)
palindrome=palindrome(num)
perfect_cube=perfect_cube(num)
perfect_square=perfect_square(num)
perfect=perfect(num)
prime=prime(num)
print("Parity ",parity)
print("Palindromic ",palindrome)
print("Perfect Cube ",perfect_cube)
print("Perfect Square ",perfect_square)
print("Perfect ",perfect)
print("Prime ",prime)
elif isinstance(num,float):
ans=input("Error! A number with a fractional part is not natural
number!\nDo you want to ignore the fractional part and continue?
Y/N :")
if ans=="Y" or ans=="y":
num=int(num)
parity=parity(num)
palindrome=palindrome(num)
perfect_cube=perfect_cube(num)
perfect_square=perfect_square(num)
perfect=perfect(num)
prime=prime(num)
print("Parity ",parity)
print("Palindromic ",palindrome)
print("Perfect Cube ",perfect_cube)
print("Perfect Square ",perfect_square)
print("Perfect ",perfect)
print("Prime ",prime)
elif ans in ['N','n']:
exit()
else:
ans=input("Error! Negative number input is invalid!\nDo you want to
ignore the sign and cotinue? Y/N :")
if ans=="Y" or ans=="y":
num=abs(num)
if isinstance(num,int):
parity=parity(num)
palindrome=palindrome(num)
perfect_cube=perfect_cube(num)
perfect_square=perfect_square(num)
perfect=perfect(num)
prime=prime(num)
print("Parity ",parity)
print("Palindromic ",palindrome)
print("Perfect Cube ",perfect_cube)
print("Perfect Square ",perfect_square)
print("Perfect ",perfect)
print("Prime ",prime)
elif isinstance(num,float):
ans=input("Error! A number with a fractional part is not natural
number!\nDo you want to ignore the fractional part and continue?
Y/N :")
if ans=="Y" or ans=="y":
num=int(num)
parity=parity(num)
palindrome=palindrome(num)
perfect_cube=perfect_cube(num)
perfect_square=perfect_square(num)
perfect=perfect(num)
prime=prime(num)
print("Parity ",parity)
print("Palindromic ",palindrome)
print("Perfect Cube ",perfect_cube)
print("Perfect Square ",perfect_square)
print("Perfect ",perfect)
print("Prime ",prime)
elif ans in ['N','n']:
exit()
elif ans in ['N','n']:
exit()
else:
exit()
NOTE: IF YOU HAVE ANY DOUBTS PLEASE
COMMENT..
i need it in a simple python Homework Assignment 2: 6P's of a number Due Date...
A positive integer is said to be a perfect number if it equals the sum of its positive divisors (excluding the number itself). As an example, 6 is aperfect number because its divisors, 1, 2, and 3 sum up to 6. The first four perfect numbers are 6, 28, 496, 8128. Write a C program that asks the user to enter a number and checks if the number is perfect. Your program should run interactively until the user quits. Try...
Assignment Develop a program to analyze one or more numbers entered by a user. The user may enter one or more numbers for analysis. Input should be limited to numbers from 1 through 1000. Determine if a number is a prime number or not. A prime number is one whose only exact divisors are 1 and the number itself (such as 2, 3, 5, 7, etc.). For non-prime numbers, output a list of all divisors of the number. Format your...
Using python 3.6 How do I incorporate 0 or negative input to raise an error and let the user try again? like <=0 #loop to check valid input option. while True: try: choice = int(input('Enter choice: ')) if choice>len(header): print("Invalid choice!! Please try again and select value either:",end=" ") for i in range(1,len(header)+1): print(i,end=",") else: break choice = int(input('\nEnter choice: ')) except ValueError as ve:print('Invalid response, You need to select the number choice from the option menu') # Catch your...
In python 3, 1. Write a program that takes a number of credit hours and returns a classification as follows: 29 credits or less: freshman; 30-59 credits: sophomore; 60-89 credits: junior; 90+ credits: senior. 2. Use a loop to valid input such that users can only enter positive numbers. 3. Use a loop to allow the user to keep entering credit hours and receiving classifications until they quit. All code must be in a function. I suggest the following structure:...
Is Prime Number In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a program that asks the user to enter a positive integer, and outputs a message indicating whether the integer is a prime number. If the user enters a negative integer, output an error message. isPrime Create a function called isPrime that contains one integer parameter, and returns a boolean result. If the integer input is a prime number, then this function returns...
please prove proofs and do 7.4 7.2 Theorem. Let p be a prime, and let b and e be integers. Then there exists a linear change of variahle, yx+ with a an integer truns- farming the congruence xbx e0 (mod p) into a congruence of the farm y (mod p) for some integer 8 Our goal is to understand which integers are perfect squares of other inte- gers modulo a prime p. The first theorem below tells us that half...
Need help debugging. first class seems fine. second class is shooting an error on s = super.getString(prompt); third class is giving me an error in the while loop where int num = console.getInt("Enter an integer:"); //-------------------------------------------------------------------------- import java.util.Scanner; public class Console { private Scanner sc; boolean isValid; int i; double d; public Console() { sc = new Scanner(System.in); } public String getString(String prompt) { System.out.print(prompt); return sc.nextLine();...
python 11.8 Multiple committees The eventual goal of this assignment is to compute the total number of ways of forming a collection of committees from an academic department of n professors. The first task is to write a function called committee to compute the number of ways of forming a single committee with members from a collection of n people. This is the same as compușing the number of ways of choosing r people out of n to sit at...
I need to write a paint job estimator program in python. I have most of it down but i keep getting errors and I dont know how to fix it or what im doing worng specs: A painting company has determined that for every 350 square feet of wall space, one gallon of paint and six hours of labor are required. The company charges $62.25 per hour for labor. Write a program call paintjobestimator.py that asks the user to enter...
Here is the assignment: Fibonacci or Prime number iterator: Design a menu driven program that performs the user’s choice of the following functions the program exits should also be a user’s choice. Menu Item 1: Fibonacci number iterator, here you are to define an iterator class named FibonacciIterator for iterating Fibonacci numbers. The constructor takes an argument that specifies the limit of the maximum Fibonacci number. For example, prompt the user for size, use the size to call FibonacciIterator(“user input”)...