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
To ease giving access to network resources for employees, you decide there must be an easier way than granting users individual
scoundrel [369]

Answer

The intranet security model

Explanation:

This is an enterprise system that processes user information for security  and access authentication. It prevents unauthorized users, who are not part of the network resources from capturing these information.

The intranet security model is an efficient security procedure that incorporates web security  access control in keeping information safe over the intranet. It is also useful in encryption and decryption techniques.

4 0
3 years ago
How does a computer work
ivann1987 [24]

Answer:

computer works on electricity

Explanation:

6 0
2 years ago
Each time an end user clicks a hyperlink, the browser generates a(n) _____ page request that is sent to the designated web serve
irina1246 [14]

Answer:

HTTP GET

Explanation:

The Hypertext Transfer Protocol (HTTP) is designed to enable communications between clients and servers and it uses the GET method to request data from the specified resource using the TCP/IP Internet protocol.

4 0
2 years ago
Question 1(Multiple Choice Worth 5 points)
vlabodo [156]

Answer:

Information assurance

Explanation:

Data theft can be defined as a cyber attack which typically involves an unauthorized access to a user's data with the sole intention to use for fraudulent purposes or illegal operations. There are several methods used by cyber criminals or hackers to obtain user data and these includes DDOS attack, SQL injection, man in the middle, phishing, etc.

Information assurance is a broad category that is typically used by cybersecurity or network experts to protect sensitive user information such as passwords, keys, emails, etc., in both digital and hard-copy forms

6 0
3 years ago
A client reports the client has been experiencing increased stress at work. The client has been managing the stress by drinking
katovenus [111]

Answer:

d. The client has no adaptive coping mechanisms.

Explanation:

The reduction of anxiety felt by the clients is reduced by the Clients in either the functional ways or dysfunctional ways.

The first thing done by the nurse was to find out the techniques used by the client in past and help the client to enhance and identify those most beneficial strategies .The next step is done by the client and the nurse to find out the maladaptive strategies such as alcohol use,social withdrawal and swap them with adaptive strategies which are suitable for the client's cultural,personal and spiritual values.

The nurse should not suggest the client to give up coping mechanism without offering other mechanism even if the client is having the maladaptive strategies.

4 0
3 years ago
Other questions:
  • You use_____ to view an XPS file
    10·1 answer
  • A _____________ is a method of controlled entry into a facility and provides access to secure areas such as a research lab or da
    10·1 answer
  • ______ is an example of unauthorized access to your computer or accounts.
    14·1 answer
  • What is output when the CarTest application is run? Why?
    11·1 answer
  • To share a document in my online electronic journal, I should select the option to _____.
    14·1 answer
  • ( Game Design) The companies who get video games out to consumers are called:
    12·1 answer
  • To communicate with an expansion card, one part of the ____ bus runs between RAM and the processor; the other part runs between
    13·1 answer
  • You can change the transparency of a picture used as a slide’s background with the ____.
    10·1 answer
  • When discussing the business requirements of a WLAN design, what is the first question that should be posed
    15·1 answer
  • Write a method that computes the sum of the digits in an integer. Use the following method header: public static int sumDigits(l
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!