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 technology concept uses computer resources from multiple locations to solve a common problem?
kramer

Answer: Sounds like you are talking about “Distributed memory systems” which use multiple computers to solve a common problem, with computation distributed among the connected computers (nodes) and using message-passing to communicate between the nodes.

8 0
3 years ago
To find resources on the Internet for your courses, you may need to use a search engine. Suppose that you are collecting informa
tekilochka [14]

Answer:

d. "Columbus, Wisconsin"

Explanation:

mark me brainliest please

8 0
3 years ago
Based on this information, what is their gross income for six months? Roderick
alexira [117]
Multiply what he makes a month by six
8 0
2 years ago
Create a class called Book with the following properties using appropriate data types: Title, Author, numberOfPages, Create a se
tamaranim1 [39]

Answer:

I don't know the answer sorry

7 0
3 years ago
Which version of Windows was considered an operating environment rather than an operating system?
maksim [4K]
The answer is A. Windows 1.O
4 0
3 years ago
Other questions:
  • What happens to formulas with relative cell references when they are copied using the fill handle?
    12·1 answer
  • When creating an input/ output table, where do you enter the formula?
    5·1 answer
  • Hi! I'm Kayla! I was wondering who does homework on the weekends... anybody?? I guess almost everyone, including me. Anyways, le
    13·2 answers
  • Using the XML Document below (library with books), define the following queries in XQuery: (a) Give the titles of all Books sort
    11·1 answer
  • Type the correct answer in the box. Spell all words correctly.
    7·2 answers
  • What is string literal in Java?
    5·1 answer
  • How do you enter the decimal 73 into the computer?
    11·1 answer
  • ¿Qué ayuda nos proporcionan las herramientas tecnológicas en estos tiempo de pandemia? ayudaaaaa plis
    9·1 answer
  • What does the following code print? time_of_day = ["morning", "afternoon", "evening"] for word in time_of_day: print "Good " + w
    15·1 answer
  • You have this code in your program.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!