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
Firlakuza [10]
2 years ago
13

Write a recursive method called, doMyMath, which takes as input any positive integer and calculates the factorial (use comments

for necessary items).
Computers and Technology
1 answer:
gulaghasi [49]2 years ago
6 0

Answer:

def doMyMath(n):  

    if n == 1:  

         return n  

    else:  

         return n*doMyMath(n-1)  

Explanation:

This line defines the function

def doMyMath(n):  

This line checks if n is 1. If yes, it returns n (1)

    if n == 1:  

         return n  

If otherwise, it calculates the fibonacci recursively

    else:  

         return n*doMyMath(n-1)  

To call the function from main, you can use:

print(doMyMath(5))

or

num = int(input("Number: "))   --- This gets the number from user

print("Result: ",doMyMath(num)) --- This calculates the factorial

<em>This question is answered in Python</em>

You might be interested in
It is not possible to use keywords to search for themes. true or false.
Drupady [299]
False my dude .........................
3 0
3 years ago
I am having trouble with this python question. I am in a beginner level class also so any solution that isn't too complex would
Delicious77 [7]

The code:

filename = input("> ")

with open(filename, "r") as file:

   items = file.read()

   items = items.split("\n")

   for index, item in enumerate(items):

       items[index] = item.split("\t")

   for item in items:

       if item[3] == "Available":

           print(f"{item[1]} ({item[0]}) -- {item[2]}")

Explenation:

1. We make the user enter the file's path, in our case "food.txt". This does only work if the .txt file is in the <u>same</u> directory as our code.

2. We get the content of our .txt file with the "open" function. If we use the "open" function inside of a "with" statement we don't have to deal with closing the file after we opened it. The file will close as soon as we exit the statement. The argument "r" indicates that we only want to read the file, not do anything else with it.

3. However the variable "file" doesn't contain the <u>contents</u> of "food.txt", only the class object of our file (if you try "print(file)" you'll only get nonsense). We can simply get the content of the file by calling ".read()" after.

4. We can separate this long str using the ".split()" function. The split function seperates a string by another sertain string (in our case "\n", since the different items are seperated by a newline). Now "items" is a list of strings.

5. Next we go through all items in "items" and separate them by "\t", again using the ".split()" function. Enumerate makes a list of indexes and values from another list (in our case, "items").

6. Now we have a list of lists of strings. The only thing left to do is go through every item and print it if the item's third item is equal to "Available" (notice that this is case-sensative). And print out the result in the desired format.

The code works for me, please ask me if there is anything you don't understand (or if the code is incorrect). Happy to help :D

5 0
2 years ago
Which statement is true? Select 3 options.
irina1246 [14]

Answer:

The statements which are true are;

  • A user-defined data type can include other user-defined data types
  • A user-defined data type is defined using a class
  • A user-defined data type can include a list

Explanation:

A user-defined data type (UDT) is a datatype that is defined and derived by the use of the datatypes which preexist including existing user-defined datatypes and the built-in datatypes

It is therefore true that a user-defined data type can include other user-defined data types

A class is a user-defined data type that contains both its member data and member functions, that can be used when an instance of the class is first created

Therefore, a user-defined data type is defined using a class

In a user-defined data type, a variable has actual data within it which can include an array or list

Therefore a user-defined data type can include a list.

3 0
2 years ago
Read 2 more answers
Are all the computer users known as programmer ​
Evgesh-ka [11]

Answer:

Nope

Explanation:

programmers are diff

6 0
2 years ago
*asap* Name one of the similarities between Word and Excel.
Yakvenalex [24]
The similarities are:  in both programs you can type letters, insert images, hyperlinks.
7 0
2 years ago
Other questions:
  • Write a program totake a depth (in kilometers) inside the earth as input data;compute
    15·1 answer
  • Think of a game you are familiar with and identify at least three team responsibilities which were required to make the game, on
    5·1 answer
  • convert the following c code to mips. assume the address of base array is associated with $s0, n is associated with $s1, positio
    14·1 answer
  • _____ allow(s) a user to double click with the mouse in a document to move the insertion point to a new location.
    11·1 answer
  • Which reading strategy refers to reading only the key words and phrases?
    13·2 answers
  • This is important I need help please
    14·1 answer
  • What term is defined as private data placed in a packet with a header containing routing information that allows the data to tra
    13·1 answer
  • Around what time did the Internet come around and how did it all start? Would like to know more of the history of how the intern
    12·1 answer
  • How do you give brianliest
    13·1 answer
  • What do you hope will be in/added GTA 6?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!