I have to write a pep8 program with these requirements. But whenever I try programing it I keep getting an error. Can u please tell me how to code this assignment.
Background: There are two primary methods for how strings are stored.
The C programming language is an example of one where strings are stored as an array of characters in memory (for our purposes here, each character is a single byte using the ASCII character set) terminated with a “null character” – a byte with the value 0. Thus, strings don’t have a pre-defined length and if you want to know how long a string is, you have to go and count the characters. Also, you always have to remember to declare your array 1 character longer than the actual characters. E.g. to store the word “hello” you would actually have to declare an array with 6 characters, so there is room for the “null” character at the end. Forgetting to allocate space for the null character is a common mistake in C programs. The benefit of this method is that the length of strings are not really limited in any way – they just keep going until you get to the “null” character.
The Java programming language is an example of one where strings are stored as an array of characters in memory, but the length of the string is also stored along with it using one of the integer data types supported by the language. Java uses an “int”, which is a 32-bit integer, meaning that strings can be up to 2 billion characters in length (32-bits can actually be used to represent 4 billion things, but since Java doesn’t have “unsigned” primitve data types, and the length of a string has to be positive, it only uses the positive numbers). This means that the length of a string can be known by accessing the length value in memory (saves a lot of processing on long strings) and there is less chance of errors caused by forgetting about the “null” character. The trade-off is that there is extra processing required to maintain the length value in memory and that every string uses extra memory for the length value (4 bytes in Java, 2 bytes for the PEP8)
Assignment:
Hi there! Click one of our representatives below and we will get back to you as soon as possible.