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
Given the following sequence of integers: 12, 19, 10, 4, 23, 7, 45, 8, 15 Build a heap by inserting the above set, one integer a
Gre4nikov [31]

Answer:

Check the explanation

Explanation:

Kindly check the attached images below to see the step by step explanation to the question above.

7 0
3 years ago
Which type of database program is Microsoft Access 2016?
nadya68 [22]

Answer:

O relational

Explanation:

If I'm wrong I'm so so sorry! But form my research it keeps saying its relational.

If I'm right please give me brainliest I really need it to level up so please help me!

If you don't know how to give brainliest there should be a crown underneath my answer you just have to click it.

Thank you and have a wonderful night,morning,afternoon/day! :D

6 0
3 years ago
Read 2 more answers
How much can a INIVDA 1050 TI take? (FPS wise)
mafiozo [28]

Answer:

At full graphics (ultra settings, full HD resolution), tests can range from 60-65 fps, 65.5 fps being the max.

Explanation:

You can benchmark graphics cards using in-game stress tests/benchmark tests or using a separate benchmarking software.

NVIDIA 1050 Ti's are now slightly outdated. Nevertheless, it is now significantly cheaper.

3 0
3 years ago
A Turing machine with doubly infinite tape (TMDIT) is similar to an ordinary Turing machine except that its tape is infinite to
umka2103 [35]

Answer and Explanation:

A TM with doubly infinite tape can simulate an ordinary TM. It marks the left-hand end of the input to detect and prevent the head from moving off of that end. To simulate the doubly infinite tape TM by an ordinary TM, we show how to simulate it with a 2-tape TM, which was already shown to be equivalent in power to an ordinary

TM. The first tape of the 2-tape TM is written with the input string, and the second tape is blank. We cut the tape of the doubly infinite tape TM into two parts, at the starting cell of the input string. The portion with the input string and all the blank spaces to its right appears on the first tape of the 2-tape TM. The portion to the left of the input string appears on the second tape, in reverse order.

3 0
3 years ago
Write a python program stored in file extra_credit.py that takes three different inputs from the user where : First Input: The p
LUCKY_DIMON [66]

Answer:

Check the explanation

Explanation:

print("************************************************************")

sentence = input("Enter a sentence : ").split()

replace_words = input("\nEnter the words that should be replaced : ").split()

special = input("\nEnter the replacing special Character : ")

result = []

for word in sentence:

   if word not in replace_words:

       result.append(word)

   else:

       result.append(special * len(word))

result = ' '.join(result)

print("\nThe Sentence with words censored is : " + result)

print("************************************************************")

4 0
3 years ago
Other questions:
  • To move to the most extreme right cell containing data in your worksheet, what basic key combination can you use?
    7·1 answer
  • The RAM is a type of ____ a.Main Memory b.Secondary Memory c.Human Memory d.EPROM e.EEPROM
    13·2 answers
  • Woodchucks are classified in the same family as squirrels,but in a different family than mice.Do woodchuck have more in common w
    8·1 answer
  • One of the earliest uses of an electronic digital computer involved ________.
    8·1 answer
  • How could a system be designed to allow a choice of operating systems from which to boot? What would the bootstrap program need
    14·1 answer
  • Alcohol does not affect the driver judgement
    8·2 answers
  • What do people in japan use to make anime
    5·1 answer
  • Provide three examples of software projects that would be amenable to the waterfall model. Be specific.
    11·1 answer
  • Complete the sentence.
    10·1 answer
  • What is the main coding language for netflix?
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!