Question

(for python) plaintext = "SNOWDENHASTHEDOCUMENTS" a) write an expression that returns the number of characters in...

(for python)

plaintext = "SNOWDENHASTHEDOCUMENTS"

a) write an expression that returns the number of characters in plaintext

b) write an expression that returns the number of substring "DEN" of the string plaintext

c) write an expression that returns the reversed string

Homework Answers

Answer #1

a)

Python provides len() function to calculate length of a string.

Argument to the length function is a variable which stored the string

Expression: len(plaintext)

b)

Count() function is returns the number of occurrences of a substring in a given string.

Syntax: stringvariable.count("substring")

Expression: plaintext.count("DEN")

c)There are many ways to reverse a string.Best way is to use extended sliced index.

Expression: plaintext[ : : -1]

Extended slice syntax provides  a “step” field as [start,stop,step].

Giving no field as start and stop indicates default to 0 and string length respectively and “-1” denotes starting from end and stop at the start, which reverses the string.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
python Suppose city is a variable that holds a string of at least 5 characters. Write...
python Suppose city is a variable that holds a string of at least 5 characters. Write one statement that assigns to a variable named letter the third letter of the string stored in city as an upper case letter. (Note: We'll assume the third letter of city is a letter)
Write a Python function that computes the frequency of characters in a string s. The function...
Write a Python function that computes the frequency of characters in a string s. The function should return a map where the key is the character and the value is the count. Make sure you include a main function and include comments to document your code.
Write a program that reads in a line consisting of a student’s name, Social Security number,...
Write a program that reads in a line consisting of a student’s name, Social Security number, user ID, and password. The program outputs the string in which all the digits of the Social Security number and all the characters in the password are replaced by x. (The Social Security number is in the form 000-00-0000, and the user ID and the password do not contain any spaces.) Your program should not use the operator [] to access a string element....
Write a C program that counts the number of repeated characters in a phrase entered by...
Write a C program that counts the number of repeated characters in a phrase entered by the user and prints them. If none of the characters are repeated, then print “No character is repeated” For example: If the phrase is “full proof” then the output will be: Number of characters repeated: 3 Characters repeated: f, l, o Note: Assume the length of the string is 10.
In Python: This will require you to write several functions, and then use them in a...
In Python: This will require you to write several functions, and then use them in a program. Logical Calculator The logical calculator does math, but with logical operators. In logic, we represent a bit with 0 as false and a bit with 1 as true. The logical operators are NOT, AND and OR. Bitwise logical calculations operate on each bit of the input. The NOT operator works on just one three-bit argument. NOT 011 = 100 The AND operator works...
Write a Python program to ask user input of a string, then ask user input of...
Write a Python program to ask user input of a string, then ask user input of what letters they want to remove from the string. User can either put in "odd", "even" or a number "n" that is greater than 2. When user input "odd", it will remove the characters which have odd numbers in the sequence of the string. When user input "even", it will remove the characters which have even numbers in the sequence of the string. When...
Write a function int count_consonants(char str[]) that determines and returns the number of consonants in a...
Write a function int count_consonants(char str[]) that determines and returns the number of consonants in a given string. Then write a simple main() function where you can repeatedly enter a string and then the num- ber of consonants is determined and printed on the screen (from the main() function). If the entered string is empty (it will contain only a ’\n’ then) the program should stop its execution. You can safely assume that the entered string will be not longer...
Write a Python function that takes a filename as a parameter and returns the string 'rows'...
Write a Python function that takes a filename as a parameter and returns the string 'rows' if a file was written row by row, and 'columns' if the file was written column by column. You would call the function with a command like filetype = myfunc(filename).
Write a function that takes as input an English sentence (a string) and prints the total...
Write a function that takes as input an English sentence (a string) and prints the total number of vowels and the total number of consonants in the sentence. The function returns nothing. Note that the sentence could have special characters such as dots, dashes, and so on. write a python program please.
Python Programming Build a python programming that asks the user for a three-letter substring. The program...
Python Programming Build a python programming that asks the user for a three-letter substring. The program should then proceed to read the file strings.txt. Each line in strings.txt will contain a string. Your program should then test to see how many non-overlapping occurrences of the three-letter substring occur in that string and test whether the string is a palindrome. The program should then proceed to create an output file string_stats.txt, which contains the original data on one line and the...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT
Active Questions
  • WRITE A PROGRAM ON PURE PYTHON WITHOUT USING ANY LIBRARIES LIKE PANDAS AND NUMPY - Read...
    asked 4 minutes ago
  • Question 3 What major advantage does NoSQL database systems have? NoSQL database systems data is highly...
    asked 5 minutes ago
  • Provide examples of how social science researchers study the problem of human trafficking.
    asked 16 minutes ago
  • A company that produces an expensive stereo component is considering offering a warranty on the component....
    asked 16 minutes ago
  • For the following questions, use the NJ table . For these questions. In some cases, the...
    asked 17 minutes ago
  • Suppose you are interested in finding out if Cal Poly students can accurately tell the difference...
    asked 18 minutes ago
  • many animals show a phenomena known as point restriction where they have light fur color over...
    asked 18 minutes ago
  • What is the key issue/challenge in the Business Intelligence Software at SYSCO case?
    asked 19 minutes ago
  • An experimental drug was given to a sample of 87 hospital patients with an unknown sickness....
    asked 32 minutes ago
  • 1. Translate the following code into MIPS code. Test (int i, int j)                         {        &n
    asked 33 minutes ago
  • An article reported that the average American college students spends 1 hour (60 minutes)on Facebook daily....
    asked 48 minutes ago
  • "Durable press" cotton fabrics are treated to improve their recovery from wrinkles after washing. Unfortunately, the...
    asked 57 minutes ago