I am giving away A TON of points. Can I please get some help writing this code? It is a bit confusing to me? Is it possible to write it in the simplest form possible? Task:

A Harris number is a number that is divisible by the sum of its digits. For example, the number 81 is a Harris number because the sum of its digits is 9 and 81 is divisible by 9.

A Flavius sequence is a numerical sequence that is generated under the following rules:

If n = 1, the sequence ends
if n is even, the next n is n/2
if n is odd, the next n is 3n + 1
There is a theorem that states that every positive integer n will generate a finitely long Flavius sequence. For example:

n=3: 3, 10, 5, 16, 8, 4, 2, 1
n=7: 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1
Flavius sequences are often identified as (n, sequence length), so (3, 8) or (7, 17).

Your task:

Write a program that prompts a user for an unknown number of numbers. The user will input positive integers one at a time and the system will respond whether or not the number is a Harris number and what the Flavius sequence length is. When the user enters an integer of 0 or less, the program will end and the following statistics will be displayed: The count of all Harris numbers entered and the longest Flavius sequence in the form (n, length).

Your program should have the following:

A method that determines whether or not a number is a Harris number and returns True or False
A method that calculates and returns the length of the Flavius sequence for any positive integer
A main (driving) portion of the program
Your code page should be commented appropriately. See the Number Fun program for examples of what should be included.

Solved
Show answers

Ask an AI advisor a question