Question

In: Computer Science

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 expressions

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)

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 an expression whose value is True if and only if x is a hexadecimal (Base 16) digit(0-9 plus A-F or a-f).

Solutions

Expert Solution

Q43)

a ) In octal we have digit range from 0 - 7 .

So when we have x and if we give it string then it will be in form of '0' , '1' , '2' ,... till '7'

Hence expression will that value of x must be greater than equal to 0 and less than equal to 7 .

Expression that will be : (x>='0' and x<='7')

Here we use and operator when both will be true

b) If x is a letter then it ranges from 'A' to 'Z' or 'a' to 'z'

Similarly check x for both either it is in Upper case or lower case and expression will be true when one is true

Expression that will be : (x>='A' && x<='Z') or (x>='a' && x<='z')

Here we use or operator so it will be true if any one is true

c) If x is hexadecimal then it ranges from 0 to 9 then we have A to F or we have 'a' to 'f' .

SO to write the expression we have to combine three checks i.e. First 0 to 9 Second a to f third A to F , If any one is true then expression is true

Expression that will be : (( x>='0' && x<='9') or ( x>='a' && x<='f' ) or ( x>='A' && x<='F'))

This is how we can write all three expression in one line in Python for each part

Thank You

If u like the answer then do Upvote it and have any doubt ask in comments


Related Solutions

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
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...
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
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...
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...
Assume you already have a non-empty string S, which is guaranteed to contain only digits 0...
Assume you already have a non-empty string S, which is guaranteed to contain only digits 0 through 9. It may be of any length and any number of digits may occur multiple times. Starting from the front of the string, write a loop that jumps through the characters in the string according to the following rule: Examine the current character and jump that many characters forward in the string Stop if you jump past the end of the string, or...
7. Suppose that we are given that there exists a random variable X whose distribution is...
7. Suppose that we are given that there exists a random variable X whose distribution is binomial with parameters are n = 500 and p= 0.300, and here X represents the number of desired outcomes of the random experiment and n-X is the number of undesired outcomes obtained from a random experiment of n independent trials. From this random experiment   p̂ sample proportion is found as X/n. (Round your answers to 3 decimal places in all parts.) What is the...
Solve the given initial-value problem. X' = 2    4 −1 6 X, X(0) = −1 8...
Solve the given initial-value problem. X' = 2    4 −1 6 X, X(0) = −1 8 X(t) =
Assume the random variable X has a binomial distribution with the given probability of obtaining a...
Assume the random variable X has a binomial distribution with the given probability of obtaining a success. Find the following probability, given the number of trials and the probability of obtaining a success. Round your answer to four decimal places. P(X=6), n=10 , p=0.5
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT