Task1.
1. Create a method that determines a maximum of three numbers.
Task2.
Problem:
Count the number of characters and words in each string.
f = open('text.txt')
line = 0
for i in f:
line += 1
flag = 0
word = 0
for j in i:
if j != '
' and flag == 0:
word += 1
flag = 1
elif j == ' ':
flag = 0
print(i,len(i),'симв.',word,'сл.')
print(line,'стр.')
f.close()
Differentiation: the task to count the number of lines in the file.
Task3 . Fill in the missing words or write which one the statement refers to(ref or out)
1) The parameter or argument must be initialized first before it is passed to _______
2) It is not compulsory to initialize a parameter or argument before it is passed to ________
3) Declaring a parameter to __________ method is useful when multiple values need to be returned from a function or method.
4) A parameter value must be initialized within the calling method before its use.
5) When we use _________ data is passed only in a unidirectional way (from the called method to the caller method).
6) When we use ________, data can be passed bi-directionally.
7) Passing a parameter value by ______ is useful when the called method is also needed to modify the pass parameter.
8) A called method is required to assign or initialize a value of a parameter (which is passed to an ______) before returning to the calling method.
9) It is not required to assign or initialize the value of a parameter (which is passed by _____) before returning to the calling method.
10) It is not compulsory to initialize a parameter value before using it in a calling method.
Task4. Let’s write the code for finding the minimum among of two numbers and compile program.
Test
1. What is the difference between a procedure and a function?
a) There is no difference
b) A procedure performs a task whereas a function produces information
c) A procedure produces information whereas a function performs a task
2. What is a module?
a) A module is a small section of a program
b) A module allows you to pass information into a function
c) A module is the name for a value passed into a function
3. What is a parameter?
a) Parameters are the values that are passed into a function or procedure
b) Parameters are the names of the information that is used in a function or procedure
c) A parameter is a small section of program
4. What is an argument?
a) An argument is a value that is passed into a function or procedure
b) An argument is a small section of program
c) An argument is the name of the information that is used in a function or procedure
5. What is the difference between a local and a global variable?
a) A global variable is declared so it can be used in any part of the program and a local variable is only available in a specific function
b) A local variable is declared so it can be used in any part of the program and a global variable is only available in a specific function
c) Both local and global variables can be used in any part of a program
6. What is a module-scoped variable?
a) A variable that is available in any part of the program
b) A variable that can only be used once
c) A variable that is only available in a single file or module
7. What is meant by 'executing' a function?
a) Deleting the function
b) Changing the function
c) Asking a function to run
8. Which of the following can be given an identifier?
a) Functions and procedures
b) Functions, procedures, parameters, arguments, variables and constants
c) Variables and constants
9. In the statement 'for x in range (1,5)' what type of variable is 'x'?
a) Local variable
b) Global variable
c) Module-scoped variable
10. Which of the following is a function?
a) Algorithm to draw a circle
b) Algorithm to calculate VAT on a product
c) Algorithm to create a cake
Материалы на данной страницы взяты из открытых источников либо размещены пользователем в соответствии с договором-офертой сайта. Вы можете сообщить о нарушении.