1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Neko [114]
3 years ago
15

Write a function called lucky_sevens that takes in one #parameter, a string variable named a_string. Your function #should retur

n True if there are exactly three '7's in #a_string. If there are less than three or more than three #'7's, the function should return False.
For example:
# - lucky_sevens("happy777bday") should return True.
# - lucky_sevens("h7app7ybd7ay") should also return True.
# - lucky_sevens("happy77bday") should return False.
# - lucky_sevens("h777appy777bday") should also return False.
Hint: Remember in Chapter 3.3, we covered how to use a loop to look at each character in a string. #Write your function here!
Below are some lines of code that will test your function.
You can change the value of the variable(s) to test your function with different inputs.
If your function works correctly, this will originally #print: True, True, False, False, each on their own line.

Computers and Technology
1 answer:
Morgarella [4.7K]3 years ago
6 0

Answer:

Here is the Python program:

def lucky_sevens(a_string):  # function to return true if exactly 3 sevens

   counter = 0  # counts the number of times 7 occurs in the a_string

   for i in a_string:  # loops through the a_string

       if i == "7":  # if 7 occurs in the a_string

           counter = counter + 1  #counter increases by 1 every time 7 occurs

   if counter == 3:  #if 7 occurs exactly 3 times in a_string

       return True  #returns true

   else:  # 7 occurs less or more than 3 times in a_string

       return False  # returns false

#tests the function lucky_sevens with different inputs      

print(lucky_sevens("happy777bday"))

print(lucky_sevens("h7app7ybd7ay"))

print(lucky_sevens("happy77bday"))

print(lucky_sevens("h777appy777bday"))

 

Explanation:

This program has a method lucky_sevens that has a parameter a_string which contains a string of characters. The counter variable stores the number of times 7 occurs in the string. The loop has variable i that works like an index and moves through the entire string looking for 7 in the a_string. If element at i-th index is 7 then the counter variable increments by 1. It increments by 1 at every occurrence of 7. Then if condition checks if the value of count is equal to 3. Which means that 7 occurred 3 times in the a_string. If the condition is true then True is displayed otherwise False is displayed on output screen.

You might be interested in
What is one invention that has had an impact on the way you live?<br><br>Write an essay
xz_007 [3.2K]
My phone duhhh. If I hadn’t had a phone I wouldn’t be able to send streaks...
8 0
3 years ago
Read 2 more answers
Nina is trying to learn more about how computers work. She has repeatedly read that the motherboard is the "brain” of the comput
Lady bird [3.3K]

Its

Processes the data on the computer .

5 0
3 years ago
Read 2 more answers
? Create a home page that introduces the rental car company. the page should have a header and footer. in the document body, it
Anestetic [448]
You need some more criteria. Is this a webpage? If so.. What language(s) are applicable for writing your web application. My profession is systems development, do I do a lot of fronte-end/ back-end development. I don't mind helping, just need some more information. If not what resource does this need to be created in?
7 0
3 years ago
How do you change the desktop background in the macos mojave operating system?
sleet_krkn [62]

Answer: Click the System Preferences icon on the dock. In the first row, click Desktop & Screen Saver.

Explanation: When it comes to macOS versions, Mojave and High Sierra are very comparable. The two have a lot in common, unlike Mojave and the more recent Catalina.

8 0
1 year ago
2. A data catalog identifies all of the following, except: a. Attribute data type b. Attribute range of values c. Attribute cons
alexandr1967 [171]

Answer:

c. Attribute constraints

Explanation:

A data catalog identifies all of the following, except: "Attribute constraints"

The above statement is TRUE because a Data Catalog, a metadata management service, operates by searching for key data, understand and manage data for usefulness.

Data Catalog checks on the BigQuery datasets, tables, and views and checks both technical and business metadata by identifying the following attributes:

1. Data type

2. Range of values

3. Value for Instructor ID

5 0
2 years ago
Other questions:
  • What does the headgear of a mine do
    6·2 answers
  • Which of the following is the best definition of being a “digital citizen”?
    6·2 answers
  • Consider the following code segment. int[] seq = {3, 1, 8, 4, 2, 5}; for (int k = 1; k &lt; seq.length; k++) { if (seq[k] &gt;=
    5·1 answer
  • What is the name for a hardcoded value entered into a formula ?
    8·2 answers
  • Nonverbal messages from the movie it​
    5·2 answers
  • Which of the following are examples of jobs in the allied health profession? select all that apply.
    8·1 answer
  • Which of the following is a sample IPv4 address?
    14·1 answer
  • Please help! I tried this by myself. But I am not sure if this is right.
    8·2 answers
  • What steps can you take to secure your private information?.
    8·1 answer
  • Abby has received a request for a data set of actual data for testing a new app that is being developed. She does not want the s
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!