Answer:
a group of instructions that can be used to organize a program or perform a repeated task
Explanation:
A function is a group of commands that can be called upon with extra parameters if needed.
Example:
def foo(): #defining this function and naming it foo
return True #what is performed when foo is called on
if foo() == True: #foo() is calling on a function named foo
print('yes')
Answer:
// code in C++.
#include <bits/stdc++.h>
using namespace std;
// main function
int main()
{
// variables
int n;
cout<<"Enter a positive number:";
// read number
cin>>n;
// check number is positive or not
while(n<0)
{
// if number is negative
cout<<"Wrong input!!"<<endl;
// ask again to enter again
cout<<"Enter again:";
// read number again
cin>>n;
}
// generate random number between 1 to n
int ran=rand()%n +1;
// print random number
cout<<"Random number between 1 to "<<n<<" is: "<<ran<<endl;
return 0;
}
Explanation:
Read a number from user.Then if input number is negative then ask user to enter a positive number again.After this generate a random number between 1 to n.Print that random number.
Output:
Enter a positive number:-12
Wrong input!!
Enter again:9
Random number between 1 to 9 is: 2
Answer:
def short_strings(string_list):
short_list = []
for s in string_list:
if len(s) < 20:
short_list.append(s)
return short_list
Explanation:
* The code is in Python.
- Create a function called short_strings that takes one parameter, string_list
- Create an empty list called short_list to hold the strings that are less than 20 characters
- Initialize a for loop that iterates through the string_list. Check if there are strings that are less 20 characters in the string_list. If found, put them in the short_list
- Return the short_list
9. C
10. B
Hope this helps!