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
The ping command uses the most basic interior routing protocol on the internet which is the:
Nesterboy [21]
Routing Information Protocol (RIP)
5 0
3 years ago
NEED HELP FAST TIMED !!!!
Trava [24]

Answer:

oil rings = encloses combustion by closing off the extra space between the block and the head,

crank shaft = connects the engine to the transmition through a series of mechanisms.

gasket = reduces the amount of exhaust inside the cylinder by sealing the cylinder.

Explanation:

3 0
3 years ago
Read 2 more answers
Qualífiers and absolutes shoud be taken as a warning when answering which type of question?
goldfiish [28.3K]

Answer:

<u><em>C-true or false</em></u>

Explanation:

just did it on edg 2020 and got 100%

6 0
3 years ago
Write a function that takes an integer and reverses the digits. The function returns the reversed number to main. Here is the pr
laila [671]

Answer:

The prototype part missing has been assumed to be:

int reverseNum (int num);

Code:

#include <iostream>

using namespace std;

int reverseNum(int num);

int main()

{

int num=0,result=0;

cout<<"Enter the number:";

cin>>num;

result=reverseNum(num);

cout<<"The reversed number :"<<result<<endl;

return 0;

}

int reverseNum(int num)

{

int temp=0,digit=0;

for(num;num>0;num=num/10)

{

digit=num%10;

temp=temp*10+digit;

}

return temp;

}

Explanation:

5 0
3 years ago
Gemima has outlined the steps she needs to take to complete this task.
e-lub [12.9K]

Answer:

B - Step 4.

Hope this helped! :D

6 0
3 years ago
Other questions:
  • Hot five was the famous band of which musician?
    14·1 answer
  • Which equation is correct regarding the measure of ∠MNP? m∠MNP = One-half(x – y) m∠MNP = One-half(x + y) m∠MNP = One-half(z + y)
    15·2 answers
  • What modifier should you use on a class so that a class in the same package can access it but a class (including a subclass) in
    14·1 answer
  • Money from a Coverdell Education Savings Account can be used for:
    11·1 answer
  • Match the part of the browser window to the correct description.
    9·1 answer
  • For the function definition int SomeFunc( /* in */ int alpha, /* in */ int beta ) { int gamma; alpha = alpha + beta; gamma = 2 *
    6·2 answers
  • When reading events in the Event Viewer, you need to recognize the designated levels or classifications. Which of the following
    9·1 answer
  • You use a 1200 watt hair dryer for 10 mintues a day.
    7·1 answer
  • Distributed databases and data warehouses would be considered which data model type?
    9·1 answer
  • the advertisement below is an example of a(n) the advertisement below is an example of a(n) informative advertising objective pe
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!