Strings Week1
.docx
keyboard_arrow_up
School
Grand Rapids Community College *
*We aren’t endorsed by this school
Course
117
Subject
Computer Science
Date
Dec 6, 2023
Type
docx
Pages
3
Uploaded by ConstableWildcatMaster401
Congratulations! You passed!
Grade received 71.42%
Latest Submission Grade 71.43%
To pass 70% or higher
Go to next item
1.
Question 1
Which of the expressions below select the last character in the string
"coconut"
"coconut"
?
1 / 1 point
"coconut"[-1]
"coconut"[-1
]
Correct
This expression selects the last character.
"coconut"[6]
"coconut"[6]
Correct
This expression selects the last character.
"coconut"[-6]
"coconut"[-6]
"coconut"[7]
"coconut"[7]
2.
Question 2
Which of the string slices below selects the string
"Sir"
"Sir"
from the string
"Sir Robin"
"Sir Robin"
?
1 / 1 point
"Sir Robin"[: 3]
"Sir Robin"[: 3]
Correct
This expression returns the string
"Sir"
"Sir"
.
"Sir Robin"[0 : 3]
"Sir Robin"[0 : 3]
Correct
This expression returns the string
"Sir"
"Sir"
.
"Sir Robin"[1 : 4]
"Sir Robin"[1 : 4]
"Sir Robin"[1 : 3]
"Sir Robin"[1 : 3]
3.
Question 3
Which one of the operators below can
not
be used with strings in Python?
1 / 1 point
*
*
(multiplication)
+
+
(addition)
-
-
(subtraction)
in
in
(membership)
Correct
String subtraction in not defined in Python.
4.
Question 4
What does the expression
a_str.find(sub)
a_str.find(sub)
do when the string
sub
sub
is not a
substring of the string
a_str
a_str
?
1 / 1 point
Raise an error.
Return the value
0
0
.
Return the value
None
None
.
Return the value
-1
-1
.
Correct
5.
Question 5
Which of the string format expressions below return the string
"abracadabra"
"abracadabra"
?
0 / 1 point
"{}{}{}".format("abra", "cad", "abra")
"{}{}{}".format("abra", "cad", "abra")
"{0}{0}{0}".format("abra", "cad", "abra")
"{0}{0}{0}".format("abra", "cad", "abr
a")
"{0}{1}{0}".format("abra", "cad")
"{0}{1}{0}".format("abra", "cad")
Correct
This example returns
"abracadabra"
"abracadabra"
.
"{1}{2}{3}".format("abra", "cad", "abra")
"{1}{2}{3}".format("abra", "cad", "abr
a")
This should not be selected
This example raises an index error.
6.
Question 6
Write a function
count_vowels(word)
count_vowels(word)
that takes the string
word
word
as input and returns the number of occurrences of lowercase vowels (i.e. the lowercase letters
"aeiou"
"aeiou"
) in
word
word
.
Hint:
Python has a built-in string method that can count the
number of occurrences of a letter in a string.
After you have implemented
count_vowels
count_vowels
, run the following two statements:
1
2
print
(count_vowels(
"aaassseefffgggiiijjjoOOkkkuuuu"
))
print
(count_vowels(
"aovvouOucvicIIOveeOIclOeuvvauouuvciOIsle"
))
The first statement should print
13
13
in the console. Enter the second number printed in the
console in the box below.
1 / 1 point
17
Correct
7.
Question 7
Write a function
demystify(l1_string)
demystify(l1_string)
that takes a string composed of
the characters
"l"
"l"
and
"1"
"1"
and returns the string formed by replacing each instance of
"l"
"l"
by
"a"
"a"
and each instance of
"1"
"1"
by
"b"
"b"
.
Once you have implemented
demystify
demystify
, test your function with calls below.
1
2
print
(demystify(
"lll111l1l1l1111lll"
))
print
(demystify(
"111l1l11l11lll1lll1lll11111ll11l1ll1l111"
))
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
A form contains six check boxes. Three of the check boxes are located in a group box. How many of the check boxes on the form can be selected at the same time? a. one b. two c. three d. six
arrow_forward
A button’s caption should be entered using sentence capitalization. a. True b. False
arrow_forward
Select the correct option for the question shown below.
arrow_forward
Q1: - Design a form and write a code to find the average value of N degrees using For
Next Loop. Use InputBox function to read degrees.
arrow_forward
Q2/ Design a form with title "Text color" contains text box and three buttons "red", "blue",
"yellow". When one of the three buttons is pressed, (the words on the button) are displayed in
the text box with the stated color.
arrow_forward
DORM AND MEAL PLAN CALCULATOR
A university has the following dormitories:
Allen Hall
$1,500 per semesterPike Hall $1,600 per semesterFarthing Hall $1,800 per semesterUniversity Suites $2,500 per semesterThe university also offers the following meal plans:7 meals per week
$ 600 per semester14 meals per week $1,200 per semesterUnlimited meals $1,700 per semesterCreate an application with two forms. The main form should allow the user to select a dormitory and a meal plan. The application should show the total charges on the second form.
For this assignment, you will create two forms (each form is an object). On the first form you will have two list boxes. One will display the Dormitories and the other one will display the Meal Plans. The user will select one Dorm and one meal plan. The user will then click a button the will open up a second form and show the results.
I would suggest that you store the Dormitories is a two dimensional array for name and cost. I would suggest that you…
arrow_forward
Need help with this. I attached how it should look
Create an event listener for the click event occurring with the submitButton that runs an anonymous function.
Within the anonymous function add the following if else structure:
If the pwd field fails the pattern match, display the validation message “Your password must be at least 8 characters with at least one letter and one number”.
Else if the value of the pwd field does not equal the value of the pwd2 display the validation message “Your passwords must match”.
Otherwise, set the validation message to an empty text string.
Save your changes to the file and then open project06-01 in your web browser.
Verify that you cannot submit the form if your password is less than eight characters long and does not include at least one number and one letter.
Verify that you cannot submit the form if the two passwords do not match.
arrow_forward
Question 6
Not complete
Marked out of
6.00
Flag question
a) What is the postfix notation for the following infix expression? (Do not put any spaces in your postfix expression.)
2 * 3 + 4
The result is:
b) What is the postfix notation for the following infix expression? (Do not put any spaces in your postfix expression.)
2 + 3 4
The result is:
c) What is the postfix notation for the following infix expression? (Do not put any spaces in your postfix expression.)
(97) * ( 3 + 4)
The result is:
d) What is the postfix notation for the following infix expression? (Do not put any spaces in your postfix expression.)
(7+2) / (9 + 1)
The result is:
e) What is the postfix notation for the following infix expression? (Do not put any spaces in your postfix expression.)
a(b + c d ) / e
The result is:
f) What is the postfix notation for the following infix expression? (Do not put any spaces in your postfix expression.)
9 *(1 + ( 2 + ( 3 + ( 4 + 5 ) ) ) )
The result is:
Check
arrow_forward
Using Visual Basic 2019
programming language: VB.NET
Franks Software Sales AssignmentYou have been hired by Franks Software Sales to write a program to figure the total cost to customers that order Slappy’s software packages. Discounts are given based on the number of units sold:Number of Units Sold Discount Amount
1–9 None10 – 19 20%
20 – 49 30%
50 – 99 40%100 or more 50%
Create a form similar to this:The three boxes are labels. Remember to use the Auto Size and Border Style properties. The program should read the number of units sold and figure a base cost. The units cost $99 each. A discount should then be figured and subtracted from the base cost. The subtotal, discount amount and total cost should be displayed, as currency, in the appropriate labels.Here are some screen shots of the running program:Set the tab order and access keys.Put comments in your program as to what each section is doing. Use constants for the discount rates and base price.Copy your code and paste it into a…
arrow_forward
True or False The assignment operator assigns the value that appears on its left side to the item that a ppears on its right side.
arrow_forward
Name:
Claz
4. Directions: The question or incomplete statement below is followed by four suggested answers or
completions. Select the one that is best in each case.
The code segment below is intended to display all multiples of 5 between the values start and end, inclusive.
For example, if start has the value 35 and end has the value 50, the code segment should display the values
35, 40, 45, and 50. Assume that start and end are multiples of 5 and that start is less than end.
Line 1: i + start
Line 2: REPEAT TIMES
Line 3: {
DISPLAY (i)oplev a bonin vimobn ldemyA
i + i + 5
Line 4:
Line 5:
Line 6: }
Which of the following could replace in line 2 so that the code segment works
as intended?
wlf
a0wollo 1
end - start + 1
b. end start + 6
(( end - start) / 5) + 1
d. 5 * (end - start) + 1
а.
C.
arrow_forward
using javascript
arrow_forward
The difference between check box and radio button controls is that
only one check box in a group can be checked at the same time
only one radio button in a group can be checked at the same time
you can only use the Checked property to check whether a check box is checked
you can’t have just one radio button on a form
arrow_forward
Slappy’s Software Sales AssignmentYou have been hired by Slappy’s Software Sales to write a program to figure thetotal cost to customers that order Slappy’s software packages.Discounts are given based on the number of units sold:Number of Units Sold Discount Amount1 – 9 None10 – 19 20%20 – 49 30%50 – 99 40%100 or more 50%Create a form similar to this:The three boxes are labels. Remember to use the Auto Size and Border Styleproperties.The program should read the number of units sold and figure a base cost. Theunits cost $99 each. A discount should then be figured and subtracted from thebase cost. The subtotal, discount amount and total cost should be displayed, ascurrency, in the appropriate labels.Here are some screen shots of the running program:Set the tab order and access keys.Put comments in your program as to what each section is doing.Use constants for the discount rates and base price.
arrow_forward
color: one of the following strings: 'red', 'blue', 'silver', 'white', 'black'year: year of manufacturing. A number between 1990 and 2018company: one of the following strings: 'Honda', 'Toyota', 'Ford', 'Chevrolet'model: one of the following strings: 'sedan', 'hatchback', 'SUV'Give a logical expression that evaluates to a True or False for a set of cars.
e.g. Expression for "Red SUV cars" is (color == "red" and model == "SUV")
Give an expression for "Ford sedan cars that are red or blue and were manufactured after 2000"
arrow_forward
B. Direction: Write the corresponding Visual Basic codes for the following statements.
1. Checkboxt has the label/caption "Philippines".
2. Add the item "India" in the listbox listFinalists.
3. If radiobutton1 is selected, 10 will be the value of variable teams.
4. The color of the text in textbox1 is blue.
5. Display 15% of the variable totalsales in the Labelbox labelResult.
arrow_forward
Programming Language is (C#), Thank you.
Write a code under Button named "ToUpper" given in attached figure. By clicking the button, transfer all items listed in ListBox1 to ListBox2, but surname will be uppercase.
arrow_forward
Create a list that contains 10 words and their descriptions. Your task is to have the application randomly select a word from the list and display the description to the user. User will then try to guess the word based on the clue displayed. One round of game is five chances. Once the total number of chances becomes zero, the program should prompt the user whether to keep playing or exit the application.
arrow_forward
A list box’s access key is specified in the____.
a. list box’s Text property
b. list box’s Label property
c. Access property of its identifying label
d. Text property of its identifying label
arrow_forward
2. Create an Orders application as shown in the figure below.
Orders
Number ordered:
Add
Subtract
Total ordered:
Exit
a) The interface provides a button for adding the number ordered to the total
ordered, and a button for subtracting the number ordered from the total
ordered.
b) Code the application using a class-level variable.
c) Be sure to code the text box's TextChanged and Enter event procedures.
d) Test the application. (If you add 7 and 5, and then subtract 2, 1, and 6, and
then add 10, 7, 4, and 5, the total ordered will be 29.)
arrow_forward
HW2b: R Exercises 1
Complete R Swirl 2 first! It will help you in this assignment!
Instructions: Write one R script title HW26.R that contains your answers to problems 1- 5. At the top of
the script write your name in a comment. Label each problem number using a comment and then type the
code that solves that problem. Here's an example of the script format (where you should fill in the R code to
solve each problem):
1
# Your Name
# Assignment
3 , # Thu Feb 03 07:39:07 2022
2
4
5
# 1.
6
7
type the R commands
solve problem 1
9.
# 2.
10
11
type the R commands to solve problem 2
12
13
# 3.
|14
15
etc.
1. What are the arguments for the Sequence Generation function seq() and give an example. Hint, use
the methods you have learned to search for help in RStudio.
2. Use R as a calculator to compute the following values.
а.
27(38-17)
b.
In(147)
436
V
С.
12
3. Create the following vectors in R and use R commands to answer the questions.
а 3 (5, 10, 15, 20, ..., 160)
b = (87, 86, 85,..., 56)
arrow_forward
# Write your codes here.print("Pizza Count:", Pizza.pizza_count)print("=======================")p1 = Pizza("Chicken")p1.set_toppings_info(25, 1, 4, 0)p1.display()print("------------------------------------")p2 = Pizza("Olives")p2.set_toppings_info(15, 1.5, 0, 0)p2.display()print("------------------------------------")p3 = Pizza("Sausage")p3.set_toppings_info(50, 5, 2, 0)p3.display()print("=======================")print("Pizza Count:", Pizza.pizza_count)Output:Pizza Count: 0=======================Toppings: Chicken25 calories1 g fat4 g protein0 g carbs------------------------------------Toppings: Olives15 calories1.5 g fat0 g protein0 g carbs------------------------------------Toppings: Sausage50 calories5 g fat2 g protein0 g carbs=======================Pizza Count: 3
arrow_forward
Write a Visual Basic statement that uses the Insert method to change the contents of the strWord variable from “me” to “mean”.
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:9781337508841
Author:Carey
Publisher:Cengage
Related Questions
- A form contains six check boxes. Three of the check boxes are located in a group box. How many of the check boxes on the form can be selected at the same time? a. one b. two c. three d. sixarrow_forwardA button’s caption should be entered using sentence capitalization. a. True b. Falsearrow_forwardSelect the correct option for the question shown below.arrow_forward
- Q1: - Design a form and write a code to find the average value of N degrees using For Next Loop. Use InputBox function to read degrees.arrow_forwardQ2/ Design a form with title "Text color" contains text box and three buttons "red", "blue", "yellow". When one of the three buttons is pressed, (the words on the button) are displayed in the text box with the stated color.arrow_forwardDORM AND MEAL PLAN CALCULATOR A university has the following dormitories: Allen Hall $1,500 per semesterPike Hall $1,600 per semesterFarthing Hall $1,800 per semesterUniversity Suites $2,500 per semesterThe university also offers the following meal plans:7 meals per week $ 600 per semester14 meals per week $1,200 per semesterUnlimited meals $1,700 per semesterCreate an application with two forms. The main form should allow the user to select a dormitory and a meal plan. The application should show the total charges on the second form. For this assignment, you will create two forms (each form is an object). On the first form you will have two list boxes. One will display the Dormitories and the other one will display the Meal Plans. The user will select one Dorm and one meal plan. The user will then click a button the will open up a second form and show the results. I would suggest that you store the Dormitories is a two dimensional array for name and cost. I would suggest that you…arrow_forward
- Need help with this. I attached how it should look Create an event listener for the click event occurring with the submitButton that runs an anonymous function. Within the anonymous function add the following if else structure: If the pwd field fails the pattern match, display the validation message “Your password must be at least 8 characters with at least one letter and one number”. Else if the value of the pwd field does not equal the value of the pwd2 display the validation message “Your passwords must match”. Otherwise, set the validation message to an empty text string. Save your changes to the file and then open project06-01 in your web browser. Verify that you cannot submit the form if your password is less than eight characters long and does not include at least one number and one letter. Verify that you cannot submit the form if the two passwords do not match.arrow_forwardQuestion 6 Not complete Marked out of 6.00 Flag question a) What is the postfix notation for the following infix expression? (Do not put any spaces in your postfix expression.) 2 * 3 + 4 The result is: b) What is the postfix notation for the following infix expression? (Do not put any spaces in your postfix expression.) 2 + 3 4 The result is: c) What is the postfix notation for the following infix expression? (Do not put any spaces in your postfix expression.) (97) * ( 3 + 4) The result is: d) What is the postfix notation for the following infix expression? (Do not put any spaces in your postfix expression.) (7+2) / (9 + 1) The result is: e) What is the postfix notation for the following infix expression? (Do not put any spaces in your postfix expression.) a(b + c d ) / e The result is: f) What is the postfix notation for the following infix expression? (Do not put any spaces in your postfix expression.) 9 *(1 + ( 2 + ( 3 + ( 4 + 5 ) ) ) ) The result is: Checkarrow_forwardUsing Visual Basic 2019 programming language: VB.NET Franks Software Sales AssignmentYou have been hired by Franks Software Sales to write a program to figure the total cost to customers that order Slappy’s software packages. Discounts are given based on the number of units sold:Number of Units Sold Discount Amount 1–9 None10 – 19 20% 20 – 49 30% 50 – 99 40%100 or more 50% Create a form similar to this:The three boxes are labels. Remember to use the Auto Size and Border Style properties. The program should read the number of units sold and figure a base cost. The units cost $99 each. A discount should then be figured and subtracted from the base cost. The subtotal, discount amount and total cost should be displayed, as currency, in the appropriate labels.Here are some screen shots of the running program:Set the tab order and access keys.Put comments in your program as to what each section is doing. Use constants for the discount rates and base price.Copy your code and paste it into a…arrow_forward
- True or False The assignment operator assigns the value that appears on its left side to the item that a ppears on its right side.arrow_forwardName: Claz 4. Directions: The question or incomplete statement below is followed by four suggested answers or completions. Select the one that is best in each case. The code segment below is intended to display all multiples of 5 between the values start and end, inclusive. For example, if start has the value 35 and end has the value 50, the code segment should display the values 35, 40, 45, and 50. Assume that start and end are multiples of 5 and that start is less than end. Line 1: i + start Line 2: REPEAT TIMES Line 3: { DISPLAY (i)oplev a bonin vimobn ldemyA i + i + 5 Line 4: Line 5: Line 6: } Which of the following could replace in line 2 so that the code segment works as intended? wlf a0wollo 1 end - start + 1 b. end start + 6 (( end - start) / 5) + 1 d. 5 * (end - start) + 1 а. C.arrow_forwardusing javascriptarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningNp Ms Office 365/Excel 2016 I NtermedComputer ScienceISBN:9781337508841Author:CareyPublisher:Cengage
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:9781337508841
Author:Carey
Publisher:Cengage