Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Lab 1 1 A: All math, all the time Lab 1 1 B: Show me where it is Write a method called letterPositions ( )
LabA: All math, all the time LabB: Show me where it is
Write a method called letterPositions which takes in two strings and returns a tuple. The first string
can be a phrase of any length while the second one will always be a single character. The tuple that the
method returns must contain the index of all occurrences of the second string inside the first string. Be
sure to not discriminate between upper and lower case ie: a and A should be the same character If
the resulting output is an empty tuple, simply return the empty tuple.
Outside the method, prompt the user for a phrase, a letter, and then print out the resulting tuple as per
the sample outputs.
Note: You can assume both inputs are always strings, and that the second input is always a single
character.
Sample outputs user input in bold:
Enter your phrase: bAnAna
Enter a letter: a
a appears inside your phrase in the following positions:
Enter your phrase: The only thing we have to fear is fear itself!
Enter a letter:
appears inside your phrase in the following positions:
Enter your phrase: What? There's no way that can be right!
Enter a letter:
appears inside your phrase in the following positions:
Write a method allMath which takes in two numbers as inputs and returns a tuple containing the result
of each arithmetic operation between both numbers in the following order: addition, subtraction,
multiplication, division, floor division, modulus, power. If one of the operations requires a division by
replace its result with "None". For example:
allMath would return the tuple
allMath would return the tuple
allMath would return the tuple None, None, None,
allMath would return the tuple
Outside the method, prompt the user for two numbers, pass those two numbers to allMath, and then
print out the result, as the sample outputs below show.
Note: You can assume both inputs are valid numbers ie you don't need to check if the inputs are
numbers
Hint: Remember that, while tuples are immutable, you can concatenate two tuples, much like you
would two strings.
Sample outputs user input in bold:
Enter your first number:
Enter your second number:
Your resulting tuple is
Enter your first number:
Enter your second number:
Your resulting tuple is None, None, None,
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started