Mindmap
Q1: How does random.randit (_,_) work?
Inhalt der Mindmap
Q1: How does random.randit (_,_) work?
The randit function from the random module produces a random integer from within the range established in the parentheses. For example, random.randit (1,6) would output a random integer between 1 and 6, emulating a die roll.
- Q2: What is "random" and what is the purpose of using the period (.) before randint?
- "random" refers to the Python's random module, which contains functions specific to generating random numbers. The period opens the appropriate module, in this case the random module, from which the function randit is pulled.
- print("The numbers generated are: " + str(randomNumberA) +" "+ str(randomNumberB) +" "+str(randomNumberC) +" "+ str(randomNumberD) +" "+ str(randomNumberE))
- Q3: What does the function print(_) do in the line of code above?
- The function print instructs the computer to display the programs output, in this case, text reading "The numbers generated are..." followed by five random numbers
- Q4: What is the purpose of the (+) operator in the line of code from Q3?
- When operating on strings, (+) acts as a joining operator. This is called concatenation and joins strings end-to-end.
- Q5: What is the purpose of the function str(_) in the next line of code from Q3?
- The function str(_) establishes the data type of the random number variable as a string.
- Q6: Is this variable (largest) global or local? Why?
- It is a local variable because it is defined inside of the function (getLargestRandom()).
- Q7: What does None mean?
- None is the value of the variable before the function runs.
- Q8: What is inputValue? Why is it necessary for this function?
- inputValue is defined in the program as a random integer between -1000 and 1000. It is necessary for the function because the program requires an input to compare to random numbers A-E.
- Q9: What does return do?
- Return is the command that allows the computer to give back a value for a function.
- Q10: What is the difference between declaring, defining, and calling a function?
- Declare a function with def my_function( ). This introduces the program to the function. Define the function by establishing parameters and crafting statements for the function to execute. Call the function to run using the function name and pair of parentheses: my_function ( ).
- Q11: How was the variable message built?
- The message variable was built by compounding strings. The value of each function is converted into a string and placed within the human language communicating the results of the program.
- Q11: How was the variable message built?
- Declare a function with def my_function( ). This introduces the program to the function. Define the function by establishing parameters and crafting statements for the function to execute. Call the function to run using the function name and pair of parentheses: my_function ( ).
- Q10: What is the difference between declaring, defining, and calling a function?
- Return is the command that allows the computer to give back a value for a function.
- Q9: What does return do?
- inputValue is defined in the program as a random integer between -1000 and 1000. It is necessary for the function because the program requires an input to compare to random numbers A-E.
- Q8: What is inputValue? Why is it necessary for this function?
- None is the value of the variable before the function runs.
- Q7: What does None mean?
- It is a local variable because it is defined inside of the function (getLargestRandom()).
- Q6: Is this variable (largest) global or local? Why?
- The function str(_) establishes the data type of the random number variable as a string.
- Q5: What is the purpose of the function str(_) in the next line of code from Q3?
- When operating on strings, (+) acts as a joining operator. This is called concatenation and joins strings end-to-end.
- Q4: What is the purpose of the (+) operator in the line of code from Q3?
- The function print instructs the computer to display the programs output, in this case, text reading "The numbers generated are..." followed by five random numbers
- Q3: What does the function print(_) do in the line of code above?
- print("The numbers generated are: " + str(randomNumberA) +" "+ str(randomNumberB) +" "+str(randomNumberC) +" "+ str(randomNumberD) +" "+ str(randomNumberE))
- "random" refers to the Python's random module, which contains functions specific to generating random numbers. The period opens the appropriate module, in this case the random module, from which the function randit is pulled.
- Q2: What is "random" and what is the purpose of using the period (.) before randint?
Informationen
- Beschreibung
- Computer Science Mindmap am Q1: How does random.randit (_,_) work?, erstellt von Benjamin Brandt am 16/01/2021.
- Erstellt von
- Benjamin Brandt
- Aufrufe
- 1
- Tags
- Bewertung