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
What is the key difference between UDP and TCP protocols in TCP/IP reference model?
g100num [7]

Answer:

TCP is a connection-oriented protocol, whereas UDP is a connectionless protocol. The speed for TCP is slower while the speed of UDP is faster.

5 0
2 years ago
Read 2 more answers
Please answer this a due tomorrow!!!
Masja [62]

Answer:

Please check the attachment.

Explanation:

The answers are self explanatory.

Download txt
4 0
3 years ago
which data representation system is based on the digits 0-9 and is mostly easily interpreted In real wrold situations​
alekssr [168]

Answer:

Hexadecimal  data representation system is based on the digits 0-9 and is mostly easily interpreted In real word situations​ .

Explanation:

Hexadecimal manages sixteen different figures: most often the numbers 0–9 to describe values zero to nine, and (A–F) to describe values ten to fifteen. The modern hexadecimal system was first launched into the domain of computing by IBM in 1963. An older description, with 0-9 and u-z, was practiced in 1956 by the Bendix G-15 computer.

3 0
3 years ago
Which of the following best explains why property rights are necessary in a
11Alexandr11 [23.1K]

Answer:

A. Property rights allow consumers and producers to make free

choices.

Explanation:

If the consumers and the producers have the properties, then only they can say that well this is free for you, or in other words, can make the free choices. And by no means market forces only work when everyone owns some property, as some also cannot have the property, and hence work hard to earn some property, and thus the Market force does work. And the laws have nothing to do with the free market or the non-free market. And as we saw above, the competition can exist if someone owns the property, and others do not. Hence, the correct answer is A.

5 0
4 years ago
What are other ways you could use the shake or compass code blocks in physical computing projects?
BabaBlast [244]

Answer:there are different ways of quick navigation between files and functions. ... You should use the menu 'Remove file from project' instead of deleting files. ... A Makefile generation tool for Code::Blocks IDE by Mirai Computing

7 0
3 years ago
Other questions:
  • The ____ is a new feature in versions of microsoft office, starting with office 2007; it consists of tabs, which contain groups
    5·1 answer
  • David is working in a database that organizes student exam grade information. He needs to find all students who have scored 100
    15·1 answer
  • [c++] Write a recursive function takes a word string as input argument and reverse the word. Print out the results of recursive
    14·1 answer
  • You are troubleshooting a mobile device with no sound output from the headset or external speakers.
    6·1 answer
  • What is the relevance of Address Block?​
    13·1 answer
  • Sandi wants to check the average grades in her classroom. Which loop or algorithm should she use?
    8·1 answer
  • Write aemail to brother for laptop for vitrual classes​
    7·2 answers
  • Join the class <br> The class code is hello112
    5·2 answers
  • How do i delete cookies on a chromebook?
    8·1 answer
  • failed logins or instances of denial of access to restricted files may be indicators of compromise. suggest where records of suc
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!