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
Select the correct answer.
Serga [27]

B: feasibility study

They are analyzing whether the project or application makes sense or is feasible, given the available resources, budget and projected monetary gains.

6 0
3 years ago
What is the purpose of a destructor? (g) What is the purpose of an accessor?
Shkiper50 [21]

Answer:

Destructor:-To free the resources when lifetime of an object ends.

Accessor:-To access private properties of the class.

Explanation:

The purpose of a destructor is to free the resources of the object that it has acquired during it's lifetime. A destructor is called once in the lifetime of the object that is also when  the ifetime of the object ends.

The purpose of the accessors is to access private properties of the class.Accessor cannot change the value of the private members.They are also called getters.

7 0
3 years ago
What time of year, or during what event, do companies spend the most money to advertise?
Triss [41]
A lot of times companies spend lots of money on ads during the holiday season and spend even more as it gets closer to Christmas. Some companies spend even more money during the Super Bowl.<span />
7 0
3 years ago
A news ____ website collects and displays content from a variety of online news sources, including wire services, print media, b
ale4655 [162]

Answer:

Aggregation

Explanation:

This type of website is responsible for collecting the data through RS feeds and web scrapping tools and inject the data in server side templates of highly flexible technologies like pug to display them in one space.By this the user do not will have to walk around many web sites to find the data on news he/she need. This type of news website collects it in one place.

5 0
4 years ago
Compare and contrast a linked list and an array.
Ostrovityanka [42]

Answer:

Differences between arrays and linked list are as following:-

  1. Arrays store elements in contiguous memory location while the linked list does not store elements at contiguous memory location it connects nodes at different memory location.
  2. Array has index to directly access the elements there are no indexes in linked list to directly access the elements.
  3. Linked list contains Nodes which contains the data and the address of the next Node while the array contains only the data in the block.
  4. Traversal over the arrays is easy while the traversal over the linked list is difficult as compared to arrays.
4 0
3 years ago
Other questions:
  • Frank is a writer. He needs to work for long hours and type for long periods on the computer. What injury can Frank develop?
    15·2 answers
  • Insecurely attached infants who are left my their mothers in an unfamiliar setting often will
    14·1 answer
  • Pros and cons of access to a wide range of online services when it comes to an individual's safety?
    14·1 answer
  • 11)When, if ever, will the geometric average return exceed the arithmetic average return for a given set of returns?A) When the
    6·1 answer
  • A ______ is an exact duplication of the hard drive, including data files, system files, and settings, application files, and the
    15·1 answer
  • Why is there more than one Brainly website?
    11·2 answers
  • Select the correct answer.
    12·2 answers
  • What is 4991 rounded to the nearest thousand
    10·2 answers
  • An alternative to configuring individual workstations is to establish configurations dynamically when the computers connect to t
    7·1 answer
  • True/False: Before a computer can execute a program written in a high level language, such as C , it must be translated into obj
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!