Write a function that prompts the user for an non-negative

Assignment Help Programming Languages
Reference no: EM132395778

Assignment

1 Part 1: increasing-splits tester -

To clarify Part 1 specifications, You have provided sample tests in Section 3 and a video. The behaviour implied by the sample tests and the video should be considered as required specifications in addition to what is explained below.

Description: Some positive integers N can be split into smaller pieces, such that the pieces are comprised of consecutive digits of N and such that each piece contains the same number of digits. Given an integer N and given a number of digits d, one can then ask if N can be split into pieces such that each pieces has d digits and such that the resulting sequence of numbers is strictly increasing

Design, implement and test a Python program which checks to see if a user-supplied positive integer N and a userspecified split d, are such that N can be split into pieces with d digits such that the resulting sequence is strictly increasing.

Here are the steps that your program should have: (Note that since no collection other than strings is allowed you will be working with N and d as strings)

0. The program greets the user.

1. The program asks the user if they want to test if a number admits an increasing-split of give size.

2. The program prompts the user to enter a positive integer. If the user enters an invalid input (anything other than a positive integer), the program will repeat the questions starting with step 1.

3. The program prompts the user to enter the number of digits in each piece. The program will verify that the input is valid (a positive integer which is a proper divisor of the number of digits in the first input); If the input is invalid, the program will repeat the questions starting with step 1.

4. Once the valid input is obtained, the program splits the number into pieces of specified length and displays/prints those pieces in one line (separated by commas).

5. Finally, the program reports whether or not the obtained sequence of numbers is in strictly increasing order. If there is only one piece, it is defined to be in strictly increasing order.

For this part, I provided you with starter code in file called part1_xxxxxx.py. Begin by replacing xxxxxx in the file name with your student number. Then open the file. Your solution (code) for this part must go into that file in the clearly indicated spaces only. You are not allowed to delete or comment-out or change any parts of the provided code except for the keyword pass.

1.1 The Core Function

Your solution in a2_part1_xxxxxx.py must have a function called: split_tester. You should design and test function split_tester before moving onto designing and coding the main part of the program. Here are specifications for that function:

split_tester This function has two parameters, a string N and a string d. These two strings can be assume to be such that each looks like a positive integer and such that the number of digits in N is divisible by the integer represented by d.

Since N and d are assumed to be valid i.e. meet the preconditions, they define a sequence of numbers (as specified in the examples above). The function should print that sequence of numbers in such a way that the consecutive numbers are separated by commas as shown in the test cases. Note that there cannot be a comma after the last number in the sequence.

The function should then return True if the sequences is strictly increasing and False otherwise. (Reporting, i.e. printing, whether or not the obtained sequence of numbers is strictly increasing has to be done in the main and not in the body of the split_tester function).

1.2 The User Interaction i.e. the main part of the program

Now that you have the function that performs the core functionality, you want to code the communication with the user in the main. It is also in the main that you should print the message about whether the sequence is increasing or not.

Advice: Leave error checking of the input for last. Begin by building your function first, and then the main assuming perfect input. Make sure though to leave enough time at the end to get the input checking details right.

The specifications on how your program needs to behave when communicating with the user should be inferred from the test examples and the video. You will notice that the program is required to display greetings surrounded with stars. One of your functions from Assignment 1, may be helpful for that.

2 Part 2: A Library of Functions

For this part of the assignment, you are required to write and test several functions (as you did in Assignment 1). You need to save all functions in part2_xxxxxx.py where you replace xxxxxx by your student number. You need to test your functions (like you did in Assignment 1) and copy/paste your tests in part2_xxxxxx.txt. Thus, for this part you need to submit two files: a2_part2_xxxxxx.py and a2_part2_xxxxxx.txt

2.1 min_enclosing_rectangle(radius, x, y)

Computing a smallest (axis-aligned) rectangle that encloses a set of objects in the plane is a very common computational problem arising in graphics and thus game development too. Write a function, called min_enclosing_rectangle, that has 3 input parameters. The first is a number representing a radius of a circle and the next two are two numbers representing the x- and y-coordinates of its center. Consider the smallest axis-aligned rectangle that contains that circle. The function should return the x- and y-coordinates of the bottom-left corner of that rectangle. If radius is a negative number, min_enclosing_rectangle should return None.

2.2 series_sum()

Write a function called series_sum() that prompts the user for an non-negative integer n. If the user enters a negative integer the function should return None otherwise the function should return the sumer of the following series 1000 +

1/1
2 + 1/2
2 + 1/3
2 + 1/4
2 + ... + 1/n2

for the given integer n. For example, for n = 0, the function should return 1000, for n = 1, the function should return 1001, for n = 2, the function should return 1001.25, for n = 3, the function should return 1001.3611111111111, etc.

2.3 pell(n)

Pell numbers are a mathematical sequence of numbers that help approximate the value of √ 2 (check out the Wikipedia page on Pell Numbers.

Write a function called pell that takes one integer parameter n, of type int. If n is negative, pell returns None. Else, pell returns the nth Pell number (i.e. Pn).

2.4 countMembers(s)

In this question you are not allowed to use any of the Python’s string methods (i.e. those string functions that you call with dot operator).

Say a character is extraordinary if it is one of the following: the lower case letter between e and j (inclusive), the upper case letters between F and X (inclusive), numerals between 2 and 6 (inclusive), and the exclamation point (!), comma (,), and backslash (\)

You are required to count how many times these characters appear in a string.

Write a function called countMembers that takes a single input parameter s, of type str. countMembers then returnsthe number of characters in s, that are extraordinary. Therefore, if there are two Xs in s, countMembers must count two extraordinary characters (one for each occurrence of X in s).

2.5 casual_number(s)

Imagine a customer in a bank is asked to enter a whole number representing their approximate monetary worth. In that case, some people use commas to separate thousands, millions etc, and some don’t. In order to perform a some calculations the bank needs that number as na integer.

Write a function, called casual_number(s) that has one parameter, s, as input where s is a string. Function casual_number(s) should return an integer representing a number in s. If s does not look like a number the function should return None. Note that if a string in s looks like a number but with commas, you may assume that commas are in meaningful places i.e. you may assume that s will not be a string like ’1, 1, 345’.

2.6 alienNumbers(s)

Strange communication has been intercepted between two alien species at war. NASAs top linguists have determined that these aliens use a weird numbering system. They have symbols for various numeric values, and they just add all the values for the symbols in a given numeral to calculate the number. NASA’s linguists have given you the following table of symbols and their numeric values. Since they have a lot of these numbers to compute, they want you to write a function that they can use to automate this task.

Write a function called alienNumbers that takes one string parameter s, and returns the integer value represented by s. Since aliens only know these characters you may assume that no character in s outside of this set: {T,y, !,a, N, U}.

Callenge: try to make the whole body of this function only one line long.

2.7 alienNumbersAgain(s)

NASA is very pleased with your proof-of-concept solution in the previous question. Now, they’ve designed a small chip that runs a very restricted version of python - it doesn’t have any of the string methods that you are used to. They want you to now rewrite your alienNumbers function to run without using any of those string methods you may have otherwise used. Basically, you can use a loop of some sort and any branching you’d like, but none of the string methods. Use accumulator variable as we have seen in class.’

Write a function called alienNumbersAgain, that takes a single string parameter s, and returns the numeric value of the number that s represents in the alien numbering system.

2.8 encrypt(s)

You want to send a note to your friend in class, and because you want to be respectful in class, you don’t want to whip out your phone and send a text or an email (or any other digital communication). Instead, you choose to go old school and write it out on a piece of paper and pass it along to your friend. The problem is, you don’t want anyone else to read the note as they pass it along. Luckily, your friend and you have come up with an encryption system so that nobody else can understand your message. Here’s how it works: you write out your message backwards (so, Hello, world becomes dlrow ,olleH). But you don’t stop there, because that’s too easy to crack - anyone can figure that out!

Now that you’ve written in backwards, Then you start on either side of the string and bring the characters together. So the first and the last characters become the first and the second character in the encrypted string, and the second and the second last characters become the third and the fourth characters in the string, and so on. Thus, Hello, world ultimately becomes dHlerlolwo , (notice how all punctuation, special characters, spaces, etc are all treated the same) and 0123456789 becomes 9081726354.

Write a function called encrypt, that has one parameter s where s is a string and encrypt returns a string which is the encrypted version of s.

2.9 oPify(s)

Write a function called oPify, that takes a single string parameter (s) and returns a string. This function considers every pair of consecutive characters in s. It returns a string with the letters o and p inserted between every pair of consecutive characters of s, as follows. If the first character in the pair is uppercase, it inserts an uppercase O. If however, it is lowercase, it inserts the lowercase o. If the second character is uppercase, it inserts an uppercase P. If however, it is lowercase, it inserts the lowercase p. If at least one of the character is not a letter in the alphabet, it does not insert anything between that pair. Finally, if s has one or less characters, the function returns the same string as s.

2.10 nonrepetitive(s) 

This may be quite a challenging question to solve. Slicing and remembering that you can ask if two strings (s1==s2) are the same are key to a short solution to this problem.

A nonrepetitive word is a word that does not contain any subword twice in a row.

Examples: ana is nonrepetitive.

borborygmus is not nonrepetitive, since it has subword, bor twice in a row.

abracadabra is nonrepetitive.

repetitive is not nonrepetitive since subword ti is repeated twice in a row.

grammar is not nonrepetitive since subword m is repeated twice in a row.

gaga is not s nonrepetitive since subword ga is repeated twice in a row.

rambunctious is nonrepetitive.

abcab is nonrepetitive.

abacaba is nonrepetitive.

zrtzghtghtghtq is not nonrepetitive since subword ght is repeated twice (in fact three times, but it is enough to find two repetitions to conclude that the word is not nonrepetitive).

aa is not nonrepetitive since subword a is repeated twice.

zatabracabrac is not nonrepetitive since subword abrac is repeated twice in a row.

Write a function, called nonrepetitive, that has one parameter, s, where s is a string. The function returns True if s is nonrepetitive and False otherwise.

Attachment:- Assignment.rar

Reference no: EM132395778

Questions Cloud

How you feel about the term english language learner : Discuss with students how they feel about the term English language learner. Do you agree with the author's use of the term English language learner?
Write a pseudocode to calculate the factorial of a number : Write simple pseudocode that solves the problem of getting ready in the morning to attend work or the university - Write and pseudocode to print your favourite
Analyzing best practices and their contribution to education : Write a paper of 1,500-1,750 words that addresses current best practices in education. This assignment requires that at least two additional scholarly research.
How the class relates to their goals early in the class : Adults are goal-oriented. They appreciate an educational program that is organized and has clearly defined elements. Instructors must show adult learners.
Write a function that prompts the user for an non-negative : Write a function called series_sum() that prompts the user for an non-negative integer n. If the user enters a negative integer the function should return None.
Describe the two state-local public health systems : Compare and contrast the two state-local public health systems in terms of their structure, general functions, specific services, resources, and other important
Reply post - Dietary Supplements : Assignment - Reply post 1 - Dietary supplements. Reply post 2 - Vitamin and Mineral Intake as it Relates to Mental Health
Do immediately get mad and say something : How do you react? Do you calmly consider that some other circumstances my have occurred and say nothing? Do you immediately get mad, but say nothing?
Results of continuous improvement projects : Why do many continuous improvement projects fail to control and sustain the gains they attained?

Reviews

len2395778

11/1/2019 11:50:46 PM

My assignment divide into 2 parts. First part is about increasing-split tester. I upload starter code for part 1. For part 2, there are several questions to answer. More details and rules for the assignment is in the A2.pdf file. In the A2.pdf file, there is YouTube address that lead you to show you about the example of part 1 and that is what the part 1 should be look like when the program runs. *You may not use any other collection (such as a list/array, tuple, or dictionary) in this assignment

Write a Review

Programming Languages Questions & Answers

  Implement a class called fibonacci

Implement a class called Fibonacci. This class should provide a single class method (static) with the following signature: double Fibonacci::getNthFibonacciRecursively(int n)

  Write accessors for each of the declared class variables.

Read the file and display in the listbox each record splitting out the fields, eliminating the comma delimiters and placing spaces between the fields.

  What is type casting in c#

M107 -  What is Type Casting in C#? Name the two forms of Type Castings in C#. Why is it needed and what are the access modifiers in C# - state the different ways of passing parameters to a method in C#.

  Measure the number of iterations of the inner loop

Let i measure the number of iterations of the inner loop of B3 and B4 (which count of iterations we cannot know), and let j measure the number of iterations of the outer loop (which we also cannot know). What is gj ?

  Create a logical expression

Create a logical expression that corresponds to the following statement - Complete the truth table for the expression created.

  Write the definitions of the classes described in exercise

Write the definitions of the classes described in this programming exercise and a program to test your classes. Indent code and insert comments to document your program. Program must be implemented and run as instructed.

  Write method that accepts as parameter reference

Write a method maxVal that accepts as parameter the reference to the head node of a linked list of integers. The method should return the largest value in the list.

  Create gui program which extends jframe

Create the GUI program which extends JFrame to find weighed average of your grade. You must input total points received on quizzes, midterm, and programming assignments.

  Prepare function for one integer parameter-returns integer

Prepare the C++ function which needs one integer parameter and returns the integer value. Function will double value passed to it and return doubled value.

  Designing menu for administrator to simulate transmissions

Design a menu which permits administrator to simulate transmissions of information by manually typing in login or logoff data.

  Create a work breakdown structure

Create a Work Breakdown Structure (WBS), and assign resources and cost by using a project management tool. As the IT project manager, you have been assigned a project to deploy ten (10) wireless access points in your company's warehouse.

  Why the exception should be handled by terminating program

Give an example of an exception that should cause a program to terminate. Explain why this exception should be handled by terminating the program.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd