Question

In: Computer Science

Given a String variable named sentence that has been initialized, write an expression whose value is...

Given a String variable named sentence that has been initialized, write an expression whose value is the the very last character in the String referred to by sentence.

write it in python

Solutions

Expert Solution

The following information has been provided for the question above:

  • "Screen shot of python code" for understanding of code indentation.
  • "Text format code" to copy and execute in your IDE.

NOTE: Code indentation is very important for python code execution. I used Python.3.5.1 IDE to run this program.

Screen shot of python code:

Output:

Text format code:

#Initialized a string variable named sentence
sentence="Test"

#An expression whose value is the the very
#last character in the String referred to
#by sentence
lastChar=sentence[len(sentence)-1]

#Display output
print("Initialized sentence is: ", sentence)
print("Very last character in the sentence is: ",lastChar)


Related Solutions

a) Given a variable word that has been assigned a string value,write a string expression...
a) Given a variable word that has been assigned a string value, write a string expression that parenthesizes the value of word. So, if word contains "sadly", the value of the expression would be the string "(sadly)"b) Assume that price is an integer variable whose value is the price (in US currency) in cents of an item. Write a statement that prints the value of price in the form "X dollars and Y cents" on a line by itself. So,...
Given an int variable k, write an expression whose value is the k-th character in the String variable word.
1. Given an int variable k, write an expression whose value is the k-th character in the String variable word. Assume thatword has been initialized and that the value ofk is non-negative and less than the length ofword.Example 1: if k's value is 3 andword is "spring", the value of the expression would be 'i'.Example 2: if k's value is 0 andword is "fall", the value of the expression would be 'f'.2. Given an int variable k, write an expression whose...
a. Assume that x is a variable that has been given a string value. Write an expression whose value is True if and only if x is an octal (Base 8) digits (0-7)
In Python: 1 line short expressionsa. Assume that x is a variable that has been given a string value. Write an expression whose value is True if and only if x is an octal (Base 8) digits (0-7)b. Assume that x is a variable that has been given a string value. Write an expression whose value is True if and only if x is an letter.c. Assume that x is a variable that has been given a string value. Write...
Given a String variable address, write a String expression consisting of the string "http://" concatenated with...
Given a String variable address, write a String expression consisting of the string "http://" concatenated with the variable's String value. So, if the variable refers to "www.turingscraft.com", the value of the expression would be "http://www.turingscraft.com". in java
Write a class named GasTank containing: An instance variable named amount of type double, initialized to...
Write a class named GasTank containing: An instance variable named amount of type double, initialized to 0. An instance variable named capacity of type double. A constructor that accepts a parameter of type double. The value of the parameter is used to initialize the value of capacity. A method named addGas that accepts a parameter of type double. The value of the amount instance variable is increased by the value of the parameter. However, if the value of amount is...
Python 1.)Assume that name is a variable of type String that has been assigned a value....
Python 1.)Assume that name is a variable of type String that has been assigned a value. Write an expression whose value is the last character of the value of name. So if the value of name were "Blair" the expression's value would be 'r'. 2.)Assume that word is a variable of type String that has been assigned a value. Write an expression whose value is a String consisting of the last three characters of the value of word. So if...
RUBY Write a DNA class that gets initialized with a string of nucleotide characters. An instance...
RUBY Write a DNA class that gets initialized with a string of nucleotide characters. An instance of DNA responds to the to_s, length, hamming_distance, contains, positions, and frequencies messages. Where a and b are DNA instances of the same length, the message send a.hamming_distance(b) returns the Hamming distance between a and b. a.contains(b) returns true if b appears as a substring in a, and returns false otherwise. a.positions(n) returns an array of the (zero-based) positions in which the nucleotide n...
Define a class named Document that contains an instance variable of type String named text that...
Define a class named Document that contains an instance variable of type String named text that stores any textual content for the document. Create a method named toString that returns the text field and also include a method to set this value. Next, define a class for Email that is derived from Document and includes instance variables for the sender, recipient, and title of an email message. Implement appropriate set and get methods. The body of the email message should...
demonstrate how to write a file named "hcsi 112.txt" while handling exceptions, the sentence given below...
demonstrate how to write a file named "hcsi 112.txt" while handling exceptions, the sentence given below into separate lines(i.e. each sentence begins from where the comma starts) "how are you today?, my name is Python, am easy to use, simple to write, and object oriented". Also show how to read the lines and store into a list.
Part I: Prompt the user for a single string and store it in a variable named...
Part I: Prompt the user for a single string and store it in a variable named userString. a. Use a for loop to print the string, char by char, with a dash '-' char between each. b. Use a for loop to print the string backwards, char by char, with a dash '-' char between each. Part II: Create an array of 5 strings named userStrings. Use a generalized array size. const int n = 5; string userStrings[n]; a. Populate...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT