Question

In: Computer Science

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 the value of word were "biggest" the expression's value would be "est".

Solutions

Expert Solution

# this function returns
#the last character of string
def last_character(name):
    return name[-1]

#this function return last three characters
# of a string if length of that string is >3
# else return the string
def last_three_characters(name):
    if len(name)>=3:
        return name[-3:]
    return name


print(last_character("Blair"))
print(last_three_characters("biggest"))


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,...
1. Assume that total has already been declared as a double variable and received a value,...
1. Assume that total has already been declared as a double variable and received a value, and discountRate has been declared as a double variable, you don’t need to declare them again. You write one if statement (not multiple individual if statements) for following requirements. when total is less than 50, set discountRate to 0.0; when total is equal to or greater than 50 and less than 100, set discountRate to 0.05; when total is equal to or greater than...
Assume that an int variable age has been declared and already given a value and assume...
Assume that an int variable age has been declared and already given a value and assume that a char variable choice has been declared as well. Assume further that the user has just been presented with the following menu: S: hangar steak, red potatoes, asparagus T: whole trout, long rice, brussel sprouts B: cheddar cheeseburger, steak fries, cole slaw (Yes, this menu really IS a menu!) Write some code that reads a single character (S or T or B) into...
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
Checkpoint 8.1 Assume the variable name references a string. Write a for loop that prints each...
Checkpoint 8.1 Assume the variable name references a string. Write a for loop that prints each character letter in the string. The actual print statement is provided. # What goes here? print(letter) Checkpoint 8.11 Write an if statement using the in operator that determines whether 'd' is in my_string. A print statement that might be placed after the if statement is included. # What goes here? print('Yes, it is there.') Checkpoint 8.13 Write the first if statement to complete the...
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...
Name the data type,value type and array size / name of the followings. 1) 20.4 2)...
Name the data type,value type and array size / name of the followings. 1) 20.4 2) a=5 3) [2 3 8] 4) ' 7 ' 5) ' abc' 6) pi 7) b=true 8) 20+2i 9) [ 'a' 'b' 'c' ] 10) [ 'a' ; 'b' ] 11) [1 2 ;4 5;7 8] 12) [20,21,22,23] 13) c= [a;b] 14) c= [b:a] 15) d=[b:a ; b:a] 16) magic(3) 17 uint8(20) 18) int8(d)
Declare a string variable and initialize it with your first name ( in C++)
Declare a string variable and initialize it with your first name ( in C++)
In python write a function whose input is a string. This function determines the data type...
In python write a function whose input is a string. This function determines the data type of the input string. The data types can be a float, int, or string. Most pass the following assertions: assert determine_data_type('1.2') == float assert determine_data_type('4') == int assert determine_data_type('EAS503') == str
Python Assume s is a string of numbers. Write a program that prints the longest substring...
Python Assume s is a string of numbers. Write a program that prints the longest substring of s in which the numbers occur in ascending order and compute the average of the numbers found. For example, if s = '561984235272145785310', then your program should print: Longest substring in numeric ascending order is: 14578 Average: 5 In the case of ties, print the first substring. For example, if s = '147279', then your program should print Longest substring in numeric ascending...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT