Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CS-UY 1114 Spring 2024

Homework 06

Due: 11:59pm, Thursday, March 07, 2024

Submission instructions:

● You should submit your homework on Gradescope.

● For this assignment you should turn in 4 separate .py files named according to the following pattern: hw6_q1.py, hw6_q2.py, etc.

● Each Python file you submit should contain a header comment block as follows:

"""

Author: [Your name here]

Assignment / Part: HW6 - Q1 (etc.)

Date due: March 07, 11:59pm

I pledge that I have completed this assignment without collaborating with anyone else, in conformance with the NYU School of Engineering Policies and Procedures on Academic Misconduct.

"""

Note:

● Late submissions will only be accepted if approved by the Student Advocacy. Once approved, contact our head CA Kim.

● Plagiarism or academic dishonesty will, at least, result in a zero for the assignment for the first offense, and failure of the course for subsequent offenses.

● It is important that the work required by the course is yours. You should not use ChatGPT or other AI tools for any purpose other than idea generation.

REMINDER: Do not use any Python structures that we have not learned in class.

For this specific assignment, you may use everything we have learned up to the release date of this assignment. [variables, constants, data types, numeric and boolean expressions, operators, user IO (i.e. print() and input()), number systems, the math / random modules, selection statements (i.e. if, elif, else), for- and while-loops, string methods]. Please reach out to us if you're at all unsure about any instruction or whether a Python structure is or is not allowed.

Do not use, for example, user defined functions, f-strings, string format, file i/o, exception handling, dictionaries, lists, tuples, and/or object-oriented programming, break, continue. Failure to abide by any of these instructions will make your submission subject to point deductions.

Problems:

1. Question 01: Halloween Candy Thief (hw6_q1.py)

2. Question 02: The Great A-B Swap-a-Thon (hw6_q2.py)

3. Question 03: Lexicographic Trends (hw6_q3.py)

4. Question 04: Read Between The Lines (hw6_q4.py)

Question 01: Halloween Candy Thief

On a spooky Halloween night, a candy thief is on the loose in your neighborhood! As the appointed Halloween Candy Thief Detective, your mission is to unveil the enigmatic culprit behind the missing sweets. Equipped with a list of suspects' initials and a trail of candy wrappers left behind, you must employ your investigative skills to identify the candy thief.

Your task is to craft a Python program that performs the following operations:

1. Accept two inputs: a string containing the first initials of the suspects and a string representing the candy wrappers.

2. For each suspect's first initial, verify if it is contained within the candy wrappers.

3. If a suspect's initial is discovered among the candy wrappers, designate them as the prime suspect of the candy heist and print their first initial.

4. In the event that none of the suspects are a match for the candy wrappers, the program should print 'No candy thief found'

Bear in mind these constraints:

● The first initials of the suspects will be a string containing at least one character.

● The string representing the candy wrappers consists of the initial characters from the candy names and will contain a minimum of one character.

For example, an execution could look like this:

Enter the initials of the suspects: ABCD

Enter the candy wrappers: MSKTCD

C is a candy thief suspect

D is a candy thief suspect

Enter the initials of the suspects: ABCDE

Enter the candy wrappers: WHQRS

No candy thief found

Question 02: The Great A-B Swap-a-Thon

Write a Python program that takes an integer 'max_num' as input and creates a pattern using nested loops. The pattern will be a combination of letters 'A' and 'B' in a specific arrangement.

Here's how the pattern should be generated:

1. Start with a string containing only the letter 'A'.

2. For each iteration from 1 to 'max_num', you will create a new string by following these rules:

○ Start with the previous string.

○ Replace all 'A' characters with 'B' and all 'B' characters with 'A'

○ Append the new string to the previous string.

For example, if the user enters '4' as 'max_num', the pattern would be generated as follows:

● Iteration 1: A

● Iteration 2: AB

● Iteration 3: ABBA

● Iteration 4: ABBABAAB

Make your program print the patterns during all the 'max_num' iterations.

Here is a sample execution:

Enter a positive integer 'max_num': 4

Iteration 1: A

Iteration 2: AB

Iteration 3: ABBA

Iteration 4: ABBABAAB

Here is another sample execution:

Enter a positive integer 'max_num': 5

Iteration 1: A

Iteration 2: AB

Iteration 3: ABBA

Iteration 4: ABBABAAB

Iteration 5: ABBABAABBAABABBA

Question 03: Lexicographic Trends

Write a program that asks the user to input a string containing only lower case letters (you may assume that they will do so). Your program should determine if the input is ordered in lexicographic decreasing order. If it is not in decreasing order, then your program must also print the location(index) at which the string stops being ordered in decreasing order.

Here is a sample execution:

Enter a string of lowercase letters: pkgba

pkgba is decreasing.

Here is another sample execution:

Please enter a string: abgcp

abgcp is not decreasing

It stopped being lexicographically decreasing at location 1

Question 04: Read Between The Lines

Let's say you wanted to decode a message that used the following encryption: Starting from the last character of the sentence, you must read every X-th letter(key). If the character that you land on is a number, you must skip it. For instance:

Enter an encoded string: !thnsdosdhdft7g68yyrop

Enter a key: 2

Your message is 'python!'

Above, we start at the last character, p, skip 2 (as denoted by the decryption key), and ignore the one numeric character we landed on (6):

STEP 0: !thnsdosdhdft7g68yyrop

STEP 1: ! [th] n [sd] o [sd] h [df] t [7g 6 8y] y [ro] p

STEP 2: ! n o h t y p

STEP 3: !nohtyp

STEP 4: python!

You may assume that both user inputs will always be valid. You may NOT use the reverse() string method.