Texas A&M University**We aren't endorsed by this school
Course
ENGR 102
Subject
Computer Science
Date
Jan 4, 2025
Pages
2
Uploaded by MagistrateAtomPigeon49
Lab: Topic 7 (individual) Based upon Dr. Keyser’s Original1Revised Summer 2024 SNRENGR 102 –Fall 2024 Lab: Topic 7 (individual) Deliverables: There are three deliverables for this individual assignment. Please submit the following files to zyBooks: •name_game.py •split_list.py •kaprekars_constant.py •kaprekars_challenge.py (optional) Activity #1: The Name Game (https://en.wikipedia.org/wiki/The_Name_Game) –individual This program is meant to help give you practice with string manipulation. The Name Game is a rhyming game that creates variations on a person’s name. Using a person’s name, the first syllable is replaced with various sounds in the pattern below. (X), (X), Bo-B(Y) Banana-Fana Fo-F(Y) Me Mi Mo-M(Y) (X)!X is the full name and Y is the name without the first consonant sound. Write a program named name_game.py that reads in a name from the user, then prints the rhyme using the output shown below. User input is shown in bold and red text. For names that begin with a vowel sound, the first syllable is notdropped, but is converted to a lowercase letter. Example output (using input Niki): What is your name? NikiNiki, Niki, Bo-Biki Banana-Fana Fo-Fiki Me Mi Mo-Miki Niki! Activity #2: Split list –individual This program is meant to give you practice with lists and looping on them. Write a program named split_list.py that takes as input from the user one string of a sequence of integers, with each value separated by a space. Have your program convert the input string to a list of integers, and determine where to split the list so that the sum of the numbers in the left portion is equal to the sum of the numbers in the right portion. If such a split can be made, print the contents of the left and right portions of the list after the split along with their sum. You may NOTreorder the numbers; use them in the given order. If the list cannot be split with equal sums, print a message to the screen according to the example below. You may assume the user enters valid input, but it is an arbitrary number of whole numbers. Note: You should use lists(and loops) when solving this problem. You may NOTuse the sum() function. You may NOTuse sympy or numpy. Example output (using input 3 1 8 4 3 0 5): Enter numbers: 3 1 8 4 3 0 5Left: [3, 1, 8] Right: [4, 3, 0, 5] Both sum to 12Example output (using input 8 3 4 6 3 2 9 0 1 8 3 5 8 3 2 6): Enter numbers: 8 3 4 6 3 2 9 0 1 8 3 5 8 3 2 6Cannot split evenly
Lab: Topic 7 (individual) Based upon Dr. Keyser’s Original2Revised Summer 2024 SNRActivity #3: Kaprekar’s Constant–individual 6174 is known as Kaprekar’s Constant (https://en.wikipedia.org/wiki/6174_(number)) after the Indian mathematician D. R. Kaprekar. This number can be obtained using Kaprekar’s routine:1.Take any four-digit number that has at least two different digits (add leading zeros to numbers with fewer than four digits) 2.Sort the digits in descending and then in ascending order to get two four-digit numbers, adding leading zeros if necessary 3.Subtract the smaller number from the bigger number to get a new four-digit number 4.Go back to step 2 and repeat Kaprekar’s routine will always reach its fixed point, 6174, in at most 8 iterations. Once 6174 is reached, the process will continue to yield 7641 –1467 = 6174. For example, choose 3524: For example, choose 137 (add a leading zero): 5432 –2345 = 3087 7310 –0137 = 7173 8730 –0378 = 8352 7731 –1377 = 6354 8532 –2358 = 61746543 –3456 = 3087 8730 –0378 = 8352 8532 –2358 = 6174The only four-digit numbers for which Kaprekar’s routine does not reach 6174 are repdigits (numbers where all digits are the same, such as 1111) which give 0000 after a single iteration. All other four-digit numbers eventually reach 6174, as long as leading zeros are used to keep the number of digits at four. Write a program named kaprekars_constant.py that takes in an integer from the user between 0 and 9999 and implements Kaprekar’s routine. Have your program output the sequence of numbers to reach 6174 and the number of iterations to get there. Format your output as shown below. Example output (using input 2028): Enter a four-digit integer: 20282028 > 7992 > 7173 > 6354 > 3087 > 8352 > 6174 2028 reaches 6174 via Kaprekar's routine in 6 iterations Hints: •Consider converting numbers to strings for sorting, and back to numbers for calculating •Pad the number with 0s when it has fewer than four digits (remember string concatenation?) •The list(), <listname>.sort(), and <string>.join()methods may be helpful Activity #3 challenge: More Kaprekar’s Constant (optional 2 bonus points) Modify your program from Activity 4 to compute the sum of the number of iterations required to reach 6174 (or 0000) using Kaprekar’s routine for all four-digit numbers, from 0000 to 9999. Name your file kaprekars_challenge.py. If your program calculates the total number of iterations correctly, you will receive 2 bonus points on this assignment. Example output: Kaprekar's routine takes ????? total iterations for all four-digit numbers