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
The _______ valve protects the air pump from reverse-exhaust pressure.
alexandr402 [8]
D. The answer for this is the gulp
7 0
3 years ago
What is the equivalent of film speed in digital cameras?
elena55 [62]
The equivalent of film speed in a digital camera is going to be sensitivity. This will make the correct answer B. 
3 0
3 years ago
Read 2 more answers
Need help with python coding
Ivanshal [37]

Answer:

def= definition

Explanation:

7 0
3 years ago
Read 2 more answers
Where can I learn how you hack?​
morpeh [17]

Answer:

www.udemy.com

5 0
3 years ago
Read 2 more answers
Implementing information systems has economic, organizational, and behavioral effects on firms. Information technology, especial
soldi70 [24.7K]

Answer: Economic

Explanation: Economic impact can be explained as the effect of a certain action, policy or action on the economy of an organization, country measured in terms of business revenue, gain or profit, impact on manufactory or production cost, inflation, monetary value and so on.

In the scenario above, the economic effect or impact of implementing information technology is highlighted in terms of lower cost of market participation, shrinkage in size of firms due to external participation and so on.

5 0
3 years ago
Other questions:
  • Click _______ to add a new column to a table.
    12·2 answers
  • What contains the computer brain the central processing unit
    8·2 answers
  • can An intelligent workplace uses technology to allow workers to be productive whether they are in the office or working from ho
    12·1 answer
  • Which of the following statements is true regarding the e-mails that were collected from Marina and Rita's Cupcakes' key employe
    11·1 answer
  • What is sun and what does it do?
    12·2 answers
  • The administrators of Tiny College are so pleased with your design and implementation of their student registra- tion and tracki
    13·1 answer
  • Richard needs to copy information from another slide presentation that uses a different design template. To ensure that the info
    10·1 answer
  • PLEASE HELP <br> Which of the following best describes the existence of undecidable problems?
    7·1 answer
  • Write short notes about monitor printer and speaker​
    14·2 answers
  • In disc brakes, pads are forced against the of a brake disc​
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!