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
Ethics issues are significant in the area of online privacy because laws have not kept pace with the growth of the Internet and
raketka [301]

Answer:

The answer is "True"

Explanation:

In the given statement some information is missing that is "True or false"

Internet security is the scope of the privacy and security of the electronic exchange of data. It's a common term that refers to something like many factors, technologies, and technology used to protect records, contact, and interests, confidential and private.

  • The security of the Internet is recognized as the privacy of the User.
  • It is secure and unique passphrases or two-factor authentication.
7 0
3 years ago
a new client has indicated that they are exercising due to advice from their physician, but they are generally amotivated. what
Orlov [11]

The factor that is a best choice for the personal trainer in their initial meeting is option a: Inquire further about what their motives are for participating.

<h3>What are the motives in motivation?</h3>

Psychologists is known to have shared motives into three types which are:

  • Biological motives
  • Social motives
  • Personal motives.

Note that the goal that is to be meant is for the fulfillment of  the client want or their  need.

Therefore asking the right question will go a long way in satisfying them. So, The factor that is a best choice for the personal trainer in their initial meeting is option a: Inquire further about what their motives are for participating.

Learn more about personal trainer from

brainly.com/question/19462080
#SPJ1

A new client has indicated that they are exercising due to advice from their physician, but they are generally amotivated. What would be the best choice for the personal trainer in their initial meeting?

Inquire further about what their motives are for participating.

Create a plan for overcoming barriers.

Establish short- and long-term goals.

Start establishing an emotional support system.

5 0
2 years ago
Why do we use Boolean Logic operators when searching a topic?
gizmo_the_mogwai [7]
We use Boolean Logic operators because it saves more time when searching a topic. This connects pieces of information in a search allowing you to find exactly what you are looking for.
6 0
3 years ago
You use the ____ operator to reverse the meaning of a boolean expression.
charle [14.2K]
!  actually it means not, which reverses a boolean.
8 0
3 years ago
I need help please :((((<br> I need it in python
Bezzdna [24]
Take this one step at a time. Your teacher has given you the code for step 1. Now write step 2. Then 3, and so on.

For step 2: if you're using Python v2.x you'd use a line like

guess = int( raw_input( "Take another guess: " ) )

For Python v3.x it would be:

guess = int( input( "Take another guess: " ) )

Break it down into small pieces, it's not a complicated assignment.
7 0
3 years ago
Other questions:
  • An expression involving byte, int, and literal numbers is promoted to which of these?
    12·1 answer
  • (15 POINTS) When an error is made in HTML code, the browser does what?
    11·1 answer
  • A browser is used for creating Web pages. true or false?
    5·2 answers
  • In the code snippet, what is the “win” part called in programming?
    12·1 answer
  • A website is a collection of​
    12·2 answers
  • What makes these Pokémon special?
    9·2 answers
  • You were recently hired by a small start-up company. The company is in a small office and has several remote employees. You have
    15·1 answer
  • Find the distance between the points.<br><br><br>(5,-2),(-6,-2)
    12·1 answer
  • Does The ps5 digital have a disc drive even Though ps4 games are not compatible
    6·1 answer
  • What are the value and data type (float, int, bool, or str) of this expression:<br> 5 // 2
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!