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
Where are parameters such boot order, processor voltage, motherboard raid, hardware virtualization support, and overclocking con
ololo11 [35]

This is configured on the BIOS Setup. During computer start-up usually for windows system this can be accessed via pressing on ESC or Function keys on immediate start up.

6 0
2 years ago
Plsss help me<br>give two examples of problems that can occur when sytems do not work properly​
melomori [17]

Answer:

Explanation:

1. There can be a run out of something ex. The water cycle we could run out of water if evaporation stops happening

2. Something wont happen ex. In a shoe factory if no one is boxing the shoes the shoes don’t get boxed.

Hope this helps

6 0
2 years ago
Which components are involved with input? Output? Processing? Storage?
VMariaS [17]

Answer: Output

input keyboard mouse joystick graphics tablet trackball touchpad touchscreen microphone sensor      

Processing     processor (CPU) processor (GPU) memory motherboard

Output printer monitor touchscreen plotter speakers headphones motor data projector

Explanation:

5 0
2 years ago
Read 2 more answers
python Which data type is the best choice to store the number of wins associated with each basketball team in the NBA
Sveta_85 [38]

Answer:

integer

Explanation:

this data type must be  a number, but it will always be  a whole number, so boolean is not appropriate. This means that it will be integer data type

4 0
3 years ago
Read 2 more answers
According to Android’s suggested user interface standards, repeatedly pressing the app icon on an app’s action bar will eventual
marusya05 [52]

Answer:

False

Explanation:

No app icon on app's action bar will move the device  to its home screen.It is not a valid statement.

8 0
2 years ago
Read 2 more answers
Other questions:
  • Victoria enjoys laughing with her friends as they walk around the track after school. Which best describes her hate rate during
    5·1 answer
  • 4
    10·1 answer
  • The date June 10, 1960, is special because when it is written in the following format, the month times the day equals the year:
    5·1 answer
  • Problems and Exercises 16 through 43 are based on the entire ("big" version) Pine Valley Furniture Company database. Note: Depen
    13·1 answer
  • A user purchased a new smart home device with embedded software and connected the device to a home network. The user then regist
    5·1 answer
  • The Department Manager researches new data platforms for the company and requests a list of essential features. Which essential
    6·1 answer
  • In Scheme, the form (symbol-length? 'James) will return: Group of answer choices 0 5 6 error message
    11·1 answer
  • Which pickaxe in minecraft to use?
    14·1 answer
  • Select the correct answer. Who takes care of the final layout of the product that meets the standards set by UX designers? A. we
    15·1 answer
  • The disk you inserted was not readable by this computer
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!