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
Which command is located in the Action Settings dialog box that allows a user to set a linked or embedded object as a trigger to
aev [14]

Answer:

Object action was the answer.

Explanation:

3 0
2 years ago
Read 2 more answers
Which of the following is an example of an application software?
pishuonlain [190]
Word processing software
6 0
2 years ago
Which technology do online storesusually use to present customized content?
k0ka [10]

Answer:

real time analytics technology

Explanation:

Online stores usually use real-time analytics technology to present customized content. Explanation: Real-time analytics is gaining popularity nowadays. It is basically the procedure of measuring and preparing the data as it enters the database

8 0
2 years ago
list the version of Windows you are using XP, Windows7, Windows8 and then explain the steps you will use to find the programs
zhannawk [14.2K]

The type of windows I am using is:Windows 8.1
7 0
3 years ago
Computer are most wonderful creation of 21st century how ?​
son4ous [18]

Answer:

It can do all the functions at a speedy rate and also helps us to search and progress in our homes and businesses. A computer can therefore be called a calculator with a twist for not only does it perform fast calculations, but it also has other special characteristics.

Explanation:

hope it helps you

6 0
1 year ago
Other questions:
  • Approximately what percent of desktop PCs are used for work-related purposes?
    13·2 answers
  • A Chief Information Security Officer (CISO) needs to establish a KRI for a particular system. The system holds archives of contr
    13·1 answer
  • Which of the following statements is not true? Group of answer choices
    9·1 answer
  • Which of the selection below does not represent a workable IP address?
    9·1 answer
  • Name the different views in word​
    5·1 answer
  • When you save a file for the first time, you must ____.
    15·2 answers
  • How many points do I need to be able to message people
    9·2 answers
  • 1
    7·1 answer
  • Write 3 things that can't be done without technology.
    14·2 answers
  • Three primary types of data that a forensic investigator must collect, in this order: 1.Volatile data 2.Temporary data 3.Persist
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!