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]
4 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]4 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
Write a program that grades the written portion of the driver's license exam. The exam has 20 multiple choice questions (answers
Roman55 [17]

Answer:

B

Explanation:

I guess

4 0
3 years ago
What is an input periphal
Lorico [155]
Anything that you can you to input actions or data into a computer. For example mice and keyboards are input peripherals because you use them to give the computer input of actions you want it to perform. This includes actions like opening a web browser with a mouse click or typing characters to the screen with a keyboard.

The opposite would be an output peripheral which would be something like the computer screen itself.
4 0
3 years ago
Read 2 more answers
When is historical data not useful
ValentinkaMS [17]

Answer:

to address for setting cost increase of a resource to determine the amount of money needed for a future project to plan for future years operation costs to predict sales based on past growth

7 0
3 years ago
Does anyone know? If you do please answer.
Sidana [21]
Whats the question..
6 0
3 years ago
Describe the difference between information poor and information rich society?​
den301095 [7]

Explanation:

The “Information poor” are consumers who use traditional mass media information such as television, DVDs, radios and magazines. ... On the opposite “information rich” stands for a new elite within the information society.

4 0
2 years ago
Other questions:
  • What is the first stage of perception
    6·2 answers
  • Worms often try to disguise from where they are sending data by using a bogus ip addresses instead of using an authorized ip add
    11·1 answer
  • DG Loans, a mortgage lender, was charged with a discrimination lawsuit. It alleged that the company was offering loans at higher
    13·1 answer
  • An ordinary office environment needs computers that have multiple user account settings where each user is allocated private dat
    13·1 answer
  • Pls help me with this pls
    7·2 answers
  • Another method that might be desired is one that updates the Goalie's jerseyNumber. This method will receive a new number of Jer
    9·1 answer
  • D. Chipboard
    14·1 answer
  • Write a program that will add up the series of numbers: 99, 98, 97… 3, 2, 1. The program should print the running total as well
    13·1 answer
  • If the tax percent is 15% and tax is $36 and percent discount is 10, what is the cost price?​
    12·1 answer
  • What will the following program display in the console?
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!