Concept explainers
mystr is "numberlike" if:
- mystr is not the empty string
- the first character in mystr is a digit
- the count of '.' in mystr is zero or one (can't have more than one decimal point in a number)
- every character in mystr is a digit ('0', '1', '2', ..., '9') or a decimal point ('.')
Write a simple python code in python to define the function is_numberlike(mystr), which takes a string parameter and returns a boolean result.
If mystr is numberlike, the function returns True; otherwise, the function returns False.
Hint: Check the first three requirements with decision statements, then use a for loop to iterate over mystr and check the every character is a digit or a dot
The Python code is given below with code and output screenshot
Happy to help you ?
Step by stepSolved in 4 steps with 2 images
- a) Give an example of a string that is neither in the language of R nor in S. b) Give an example of a string that is in the language of S but not R. c) Give an example of a string that is in the language of R but not S. d) Give an example of a string that is in the language of R and S. e) Design a regular expression that accepts the language of all binary strings with no occurrences of 010.arrow_forwardThe following two languages over {a,b} L1: All strings that contains at least two 'b's L2: All strings that has an 'a' as the second to last character of the stringarrow_forwardWhat characters are utilised as delimiters when you supply null as a parameter to the Split method of a string object?arrow_forward
- The countSubstring function will take two strings as parameters and will return an integer that is the count of how many times the substring (the second parameter) appears in the first string without overlapping with itself. This method will be case insensitive. For example: countSubstring(“catwoman loves cats”, “cat”) would return 2 countSubstring(“aaa nice”, “aa”) would return 1 because “aa” only appears once without overlapping itself. public static int countSubstring(String s, String x) { if (s.length() == 0 || x.length() == 0) return 1; if (s.length() == 1 || x.length() == 1){ if (s.substring(0,1).equals(x.substring(0,1))){ s.replaceFirst((x), " "); return 1 + countSubstring(s.substring(1), x); } else { return 0 + countSubstring(s.substring(1), x); } } return countSubstring(s.substring(0,1), x) + countSubstring(s.substring(1), x); } public class Main { public static void main(String[] args) { System.out.println(Recursion.countSubstring("catwoman loves cats","cat"));…arrow_forwardC Programming Write a program that reads an integer from the user (keyboard), namely n. Yourprogram should print all positive numbers that are smaller than n and whosedigits sum up to a perfect square number.(An integer is a perfect square if it hasan integer square-root for example 25) You should print the numbers in ascendingorder and print their digits separated by “:“ symbol from the least significant digitto the most significant digit on the same line as the number. At the end of eachline you should also print the sum of the digits of the number. Example:If the user enters n : 30, then the output should be as follows:1 1 14 4 49 9 910 0:1 113 3:1 418 8:1 922 2:2 427 7:2 9arrow_forwardScala Programming: Given string str, write a Scala program to create a new string where "Scala " is added to the front of a given string. If the string already begins with "Scala", return the string unchanged. Otherwise, return the string after adding "Scala ". Test the function for two strings "Scala Programming" and "Programming" inside the main method.arrow_forward
- What is the length of the following string in C:1. char* my_str = {‘c’, ‘a’, ‘t’, ‘0’, ‘d’, ‘o’, ‘g’};arrow_forward1. In using scanf the reference to data was always passed. When using printf the reference was passed for a string, but the data value was required for types such as integer. This says that what is commonly refer to as a variable actually has 3 parts: 1 - The label (sometimes called the id or name); 2 - the reference; 3 - the value. Explain to the best of your understanding what is the difference between each of these three parts, and how it changes the cognitive model or metaphor you use to understand a variable. The type of the variable (how the variable is stored and operations on the variable) are associated with what part of the variable, the label, reference, or value? 2. Which parts of the variable exist at compile time, and which parts exist at run time? 3. Harder question with more insight: Can a value be a reference? Can you think of an example? (Think of structs and arrays). 4. Even harder, this is a real world example. I read that Python has immutable primitive types (e.g.…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education