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
Question #5
stepladder [879]

Answer:

books.append({5:2})

Explanation:

got it right on edge 2020

4 0
3 years ago
Read 2 more answers
The content of each content page that uses a master page is stored in the ________________ of the master page.
Llana [10]
In the directors copy
4 0
3 years ago
How is your approach to solving how to order your coins different from how a computer might have to approach it?
Finger [1]

Answer: Computer solves the order of coins the way its programmed to while you solve the order of coins the way you want.

8 0
3 years ago
]
loris [4]
B. Which promotes a chemical reaction
5 0
3 years ago
Which of the following scanning technique attackers use to bypass firewall rules, logging mechanism, and hide themselves as usua
cestrela7 [59]

Answer: Stealth scanning technique

Explanation:

Stealth scanning technique consist of the following types of scans :

1. FIN scan

2. X- MAS tree scan

3. NULL scan

The FIN scan responds by considering port open if response in received for its packet sent with the fin flag else considered closed.

The X-MAS tree scan fires up by setting a  TCP packet with URG, PUSH, FIN flags and the port is considered open if no response.

NULL scans sends null packet and considers it to be an open port.

Stealth scanning techniques considers to get some response from the network with out actually using a handshaking and is used to bypass firewall rules, logging mechanism, and hide themselves as usual network traffic.

3 0
4 years ago
Other questions:
  • which one of these steps describe saving a newly created file. click on the save icon. minimize the file. name the file. select
    12·2 answers
  • What is the maximum transmission speed for bluetooth v3 and v4 devices?
    12·1 answer
  • Need help . business and technology
    11·1 answer
  • Information systems cannot solve some business problems. Give three examples and explain why technology cannot help
    11·1 answer
  • What is the speed of Android operating system?
    6·1 answer
  • True or False: Nanomemory applies to computers.
    13·1 answer
  • Answer if you know Javascript, html, css, python, and Ruby.
    12·1 answer
  • Why do we create user accounts to customize our preferences​
    10·1 answer
  • 8. Assuming str(rate) is "7.25," what output would be produced by the following snippet:
    15·1 answer
  • Compare and contrast sources and types of credit, including costs and benefits of installment
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!