Question: Task 2 ( of 2 ) : A Happy number is a number that eventually reaches 1 when replaced by the sum of the square

Task 2(of 2):
A Happy number is a number that eventually reaches 1 when replaced by the sum of the square
of each digit. For instance, 13 is a happy number because 12+32=10, and 12+02=1. On the other
hand, 4 is not a happy number because the sequence starting with 42=16, and 12+62=37
eventually reaches 22+02=4, the number that started the sequence, and so the process continues
in an infinite cycle without ever reaching 1. Create test cases for 2 other happy numbers and 2 non-
happy numbers.
A Perfect number is a number that is equal to the sum of its proper divisors (divisors including 1
but not itself). The smallest perfect number is 6, which is the sum of 1,2, and 3. Create test cases
for 2 other perfect numbers and 2 non-perfect numbers.
A Narcissistic number is a number that is the sum of its own digits each raised to the power of
the number of digits. For example, 153 is a 3-digit narcissistic number: 153=13+53+33. Create
test cases for 2 other narcissistic numbers and 2 non- narcissistic numbers.
Part A
ENED 1120 HW 2.1 Spring 20243
Three Python functions have been included (see HW2p1_Task2_UCusername.py file in CANVAS
where this document was accessed) to identify a number as being one of the three types listed
above: Happy(num), Perfect(num), and Narcissistic (num).
Each function has at least one syntax error and thus will not run as provided. Identify the syntax
error in each function and fix the syntax error. Also, you are encouraged to run these functions
individually to understand what they need as inputs, return as outputs, and how they determine if
the number is or is not a happy, perfect, or narcissistic number.
Part B
For this part, use the updated (no syntax errors) Python functions from Part A, and at the bottom
(where it says Start your script here), generate a Python script that will:
Ask the user to enter a whole number N.
Call the Python functions from Part A to identify and record into a single list, all numbers
n (1<= n <= N) that are perfect, narcissistic, or happy using a repetition structure (for or while
loop) and Pythons append built-in function
For each number in the list, create a different list that identifies the type of number found,
i.e. if the number if happy (h), or narcissistic (n), or perfect (p), or a combination of two or
more types (hn, hp, pn or hnp).
Output to the Python Shell (using a print statement) the list of numbers found, and the
corresponding list of number types in the format shown below. One way to do this format
is to add another loop that goes through and prints the first entry in the numbers found list
and the number type list, and continues to the second entry, third entry, etc., such that each
number is matched with its number type.
Test case:
enter a large whole number N 10
1 is hn
2 is n
3 is n
4 is n
5 is n
6 is np
7 is hn
8 is n
9 is n
10 is h

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!