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
Ludmilka [50]
4 years ago
6

The count_users function recursively counts the amount of users that belong to a group in the company system, by going through e

ach of the members of a group and if one of them is a group, recursively calling the function and counting the members. But it has a bug! Can you spot the problem and fix it?
This is the code :

def count_users(group):
count = 0
for member in get_members(group):
count += 1
if is_group(member):
count += count_users(member)
return count

print(count_users("sales")) # Should be 3
print(count_users("engineering")) # Should be 8
print(count_users("everyone")) # Should be 18
Computers and Technology
1 answer:
elena-s [515]4 years ago
6 0

Answer:

# The count variable should be defined in a global scope.

count = 0

def count_users(group):

for member in get_members(group):

 count += 1

 if is_group(member):

  count += count_users(member)

return count

 

print(count_users("sales")) # Should be 3

print(count_users("engineering")) # Should be 8

print(count_users("everyone")) # Should be 18

Explanation:

The count variable should be defined in a global scope which means that it shouldn't be defined inside the scope of the count_users function.

The reason is that count_users is a recursive function and when it is called recursively then it will be setting the count variable to 0 again and again, hence instead of keeping the count of users, it will lose the value all the time serving no purpose. But when it's defined outside the function then it will not initialized again in the recursive calls.

You might be interested in
Every telecommunication setup uses two devices: one device to transmit data and one device to receive data. Which device transmi
alexandr1967 [171]

Answer:

Cell.

Explanation:

Electromagnetic waves is a propagating medium used in all communications device to transmit data (messages) from the device of the sender to the device of the receiver.

Generally, the most commonly used electromagnetic wave technology in telecommunications is radio waves.

Radio waves can be defined as an electromagnetic wave that has its frequency ranging from 30 GHz to 300 GHz and its wavelength between 1mm and 3000m. Therefore, radio waves are a series of repetitive valleys and peaks that are typically characterized of having the longest wavelength in the electromagnetic spectrum.

Basically, as a result of radio waves having long wavelengths, they are mainly used in long-distance communications such as the carriage and transmission of data.

In the field of telecommunication, all telecommunication setup are designed and developed to make use of two network devices: one device is typically used for the transmission of data while the other device is used to receive data that are sent on the network.

Generally, cell towers are tall poles that are used to transmit frequencies to mobile phones.

3 0
3 years ago
I was able to solve the question :))
Leviafan [203]

Answer:

ill take the points anyway

Explanation:

4 0
3 years ago
What changes has Sue made so far? Check all that apply.
Alexus [3.1K]

Answer:

Its C, E, and F

Explanation:

On edg

8 0
3 years ago
Read 2 more answers
It is possible to play older console games such as those written for the nintendo game boy or sega genesis on a personal compute
timurjin [86]
Emulator««««that is the answer
5 0
3 years ago
You have decided to install the DNS server role on Nano Server. What specific type of zone configuration is not supported when u
nadya68 [22]

Answer:Active Directory-integrated

Explanation: Active Directory-integrated is the service that is introduced by the Microsoft .This service provides the directory form for functioning in Windows. It serves the purpose of active directory(AD) transferring to the Dynamic web database. Whenever the user gets connected to any website, it provides validation to qualifications . So, it does not get support the specification when there is working of DNS.

4 0
3 years ago
Other questions:
  • Write a program that asks the user to input four numbers (one at a time). After the four numbers have been supplied, it should t
    6·1 answer
  • A hard disk is divided into tracks which are further subdivided into:​
    11·1 answer
  • Grace Hopper led the development of ______, a programming language for business applications.
    6·2 answers
  • 7. When using find command in word we can search?
    7·1 answer
  • The image below shows a weather service map
    13·1 answer
  • You dad has given you his old digital scanner for your new computer. you plug it into the usb drive on your windows 8 computer b
    8·1 answer
  • Write a program that reads a list of words. Then, the program outputs those words and their frequencies. The input begins with a
    10·1 answer
  • Drag the right word to it’s definition
    13·1 answer
  • Is it better to try to prevent damage from natural disasters or to deal with disasters after they occur?
    10·2 answers
  • Draw truth table for the following logic circuit:<br><br> (Please I really need help with this)
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!