Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

OBJECTIVE: Practice using functions, for loops and while loops. BACKGROUND: Multiplying the digits of an integer and continuing the process gives the interesting result that

OBJECTIVE: Practice using functions, for loops and while loops.

BACKGROUND: Multiplying the digits of an integer and continuing the process gives the interesting result that the sequence of products always arrives at a single-digit number. For example:

 27 ---> 14 ---> 4 88 ---> 64 ---> 24 ---> 8 715 ---> 35 ---> 15 ---> 5 557 ---> 175 --> 35 ---> 15 ---> 5 26887971--->338688--->27648--->2688--->768--->336--->54--->20--->0 

The number of products necessary to reach the single-digit is called the persistence number of that integer. Thus 27 has persistence 2, 88 and 715 have persistence 3, 557 has persistence 4, and 26887971 has persistence 8. A single-digit number has persistence zero.

TASK: Write a program to determine the smallest non-negative integer with a persistence of 3, then 4, then 5, then 6, then 7. Your output must have the following format (i.e., spacing, punctuation, and wording/spelling):

 CSCI 1170 OLA110 BY student name The smallest integer with a persistence of 3 is: 39 The smallest integer with a persistence of 4 is: dd The smallest integer with a persistence of 5 is: ddd The smallest integer with a persistence of 6 is: dddd The smallest integer with a persistence of 7 is: ddddd 

IMPLEMENTATION NOTES: Within your program, define an integer-returning function, named "persistence()", that is invoked with a single (non-negative) integer argument and returns the persistence of that integer. For example,

 p = persistence(715) 

will assign a value of 3 to p.

Use as your source file name "persist.py". Don't forget to include the title line and global comments at the top of your program.

Do not use: any global variables (remember, they're "bad"), string manipulation (figuring persistence requires only numeric expressions), or lists (unnecessary and, besides, we haven't covered list manipulation yet).

This program has no explicit input (and thus does no reads). Instead it has two implicit inputs: LOW_LIMIT, set equal to 3, and HIGH_LIMIT, set equal to 7. (Note that these are capitalized identifiers to emphasize they are the Python equivalent of symbolic constants.) Your program must work equally well if these variables (that you must define and use) are set to some other non-negative integer values. (Except that LOW_LIMIT will always be less than or equal to HIGH_LIMIT.) Use these variables in your program to control the print loop. Somewhere in your program you will need a search loop; it should resemble the following:

 # Find the smallest non-negative integer with a persistence >= limit number = 1; while persistence(number) < limit: number += 1 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Theory And Application Bio Science And Bio Technology International Conferences DTA And BSBT 2011 Held As Part Of The Future Generation In Computer And Information Science 258

Authors: Tai-hoon Kim ,Hojjat Adeli ,Alfredo Cuzzocrea ,Tughrul Arslan ,Yanchun Zhang ,Jianhua Ma ,Kyo-il Chung ,Siti Mariyam ,Xiaofeng Song

2011th Edition

ISBN: 3642271561, 978-3642271564

More Books

Students also viewed these Databases questions

Question

Determine the amplitude and period of each function.

Answered: 1 week ago