Python
QUESTION A
Below we have an assignment of a string to s.
What is the index of the colon in s? You can use
find method in Python to get the answer. The
answer should be an integer.
s = 'X-DSPAM-Confidence: 0.8475'
__________
QUESTION B
What did you type to get the answer above? State the exact Python code (codes like s.split(), len(s), print('hello')).
___________
QUESTION C
Now extract only the substring 0.8475 from s with expression s[ ]. Type that expression here, for example, s[2:5], s[2:], s[:5].
___________
Code:
s = 'X-DSPAM-Confidence: 0.8475'
#B)
idx = s.find(':')
print(idx)
#C)
substr = s[idx+2:]
print(substr)
Output:
18
0.8475
Python QUESTION A Below we have an assignment of a string to s. What is the...
Select all true statements about Python string indexing: Python uses indexing operator (square brackets) to select a single character from a string Python supports indexing in both left to right and right to left Left to right indexing starts with 0 Right to left indexing starts with -1 The return type of a string index is also a string Select all the ways you can extract "rocks" out of s = "Python rocks": print(s[7:]) print(s[7:20]) print(s[-5:]) print(s[-5::1]) print(s[-5::]) Given the...
Page 3 of 7 (Python) For each substring in the input string t that matches the regular expression r, the method call re. aub (r, o, t) substitutes the matching substring with the string a. Wwhat is the output? import re print (re.aub (r"l+\d+ " , "$, "be+345jk3726-45+9xyz")) a. "be$jk3726-455xyz" c. "bejkxyz" 9. b. "be$jks-$$xyz" d. $$$" A object a- A (2) 10. (Python) What is the output? # Source code file: A.py class A init (self, the x): self.x-...
programming language in python
Solicit string from the keyboard one after another till you get a null value input (null means nothing a Carriage Return <CR> hit). During the cycle, determine the length of the key-in. If it is an odd number length (1, 3, 5, ...) then add a colon (":") before concatenating with the next string, otherwise when even number (2, 4, 6, ...) add a dash (") at the end before connecting. Discard (not re-solicit, simply ignore)...
Question 1 True and False are Boolean keywords in Python True False Question 2 0.0/1.0 point (graded) hot_plate = True if hot_plate: print("Be careful, hot plate!") else: print("The plate is ready.") The output of from running the above code is ___ "Be careful, hot plate!" "The plate is ready." "True" NameError Question 3 0.0/1.0 point (graded) vehicle_type = "Truck" if vehicle_type.upper().startswith("P"): print(vehicle_type, 'starts with "P"') else: print(vehicle_type, 'does not start with "P"') The...
IN PYTHON. We have seen examples of using the python re library. In this practice, you need to write python code and complete following tasks. (You can decide whether you want to define functions and how to organize your code. It is for your own practice.) 1). Define 10 string variables that follows the requirement given an integer, a float, a double, a float end with letter f (4.321f), Capital Letters( followed by small case letters, followed by digits, Exactly...
Python Assignment: def sliceNdice(list2, s,e): L = len(list2) if(s>0 and s<e and e+s<=L): list1 = list2[s:e+s] else: list1 = [ ] return list1 refer to the code above. What is the value of L after line 2 and we call: x = sliceNdice([3,6,9,7] 2,6) 3. Refer to the previous question. What is happening at line 4? 4. For the code shown below: for num in range (1,4): print(num) What is the first value printed
Lab2: Processing Strings Part#1 – Counting Vows Assume s is a string of lower case characters. Write a program that counts up the number of vowels contained in the string s. Valid vowels are: 'a', 'e', 'i', 'o', and 'u'. For example, if s = 'azcbobobegghakl', your program should print: Number of vowels: 5 Part#2 – Counting Bobs Assume s is a string of lower case characters. Write a program that prints the number of times the string 'bob' occurs...
Answer question in Python, show all code: 1) Improve the functionality of the (first) NumberOfVowels program from class to also print out the locations (indexes) of the vowels in the input string. Some sample interactions follow: Please enter a string: hello The number of vowel occurrences in your string is: 2 The indexes of the vowels in your string are: [1, 4] Please enter a string: pfft There are no vowels in your word. Please enter a string: bell The...
Please use Python
def findSubstrings(s):
# Write your code here
Consider a string, s = "abc". An alphabetically-ordered sequence of substrings of s would be {"a", "ab", "abc", "b", "bc", "c"}. If the sequence is reduced to only those substrings that start with a vowel and end with a consonant, the result is {"ab", "abc"}. The alphabetically first element in this reduced list is "ab", and the alphabetically last element is "abc". As a reminder: • Vowels: a, e, i,...
. Use what you learned from our First Python Program to write a Python program that will carry out the following tasks. Ask user provide the following information: unit price (for example: 2.5) quantity (for example: 4) Use the following formula to calculate the revenue: revenue = unit price x quantity Print the result in the following format on the console: The revenue is $___. (for example: The revenue is $10.0.) . . Use the following formula to calculate the...