0% found this document useful (0 votes)
5 views6 pages

1.1P: Preparing For OOP - Answer Sheet: Cd.. CD .

1.1P

Uploaded by

Hữu Tường
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views6 pages

1.1P: Preparing For OOP - Answer Sheet: Cd.. CD .

1.1P

Uploaded by

Hữu Tường
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1.

1P: Preparing for OOP – Answer Sheet


1. Explain the following terminal instructions:
a. cd (change directory): when typing the cd.. or cd .. command, this will
move the directory back one directory, also known as the parent
directory. As shown below, in the \Users\Admin directory, using the
cd.. command takes you back to the Windows directory.

the cd\ command takes you back to the root directory of the current
drive. As shown below, in the \Users\Admin directory, using the cd\
command take you to the C:\ directory.

b. ls (list): the ls command is used to list the files and directories in the
current directory (as screenshotted below)

c.
d. pwd (print working directory): the pwd command writes to standard
output the full path name of your current directory (from the root
directory) (as screenshotted below).

2. Consider the following kinds of information, and suggest the most appropriate
data type to store or represent each:

Information Suggested Data Type


A person’s name string
A person’s age in years interger
A phone number string
A temperature in Celsius float
The average age of a group of people float
Whether a person has eaten lunch boolean

3. Aside from the examples already provided in question 2, come up with an


example of information that could be stored as:

Data type Suggested Information


String A person’s gender
Integer A person’s ID number
Float A person’s height
Boolean Whether a person want continue or not
4. Fill out the following table, evaluating the value of each expression and
identifying the data type the value is most likely to be:

Expression Given Value Data Type


6 6 integer
True True boolean
a a = 2.5 2.5 float
1 + 2 * 3 7 integer
a and False a = True False boolean
a or False a = True True boolean
a + b a = 1 3 integer
b = 2
2 * a a = 3 6 interger
a * 2 + b a = 2.5 7 integer
b = 2
a + 2 * b a = 2.5 7.5 float
b = 2
(a + b) * c a = 1 10 integer
b = 1
c = 5
“Fred” + “ Smith” Fred Smith string
a + “ Smith” a = “Wilma” Wilma Smith string

5. Using an example, explain the difference between declaring and initialising a


variable.

Declaring a variable sets up its type and name, while initializing a variable assigns a
value to it. Declaration is the first step, creating the variable, and initialization is the
second step, giving it an initial value.
int x : variable x is declared
x = 10 : variable x is initialized with the value 10

6. A parameter is a variable used in a function or method to accept one or more


values as input, which can then be used in the code of that function or
method.
7. Using an example, describe the term scope.
Scope is the region in a program where a variable or identifier is defined and
can be accessed
Example of scope:
def print_name():
name=”Le Huu Tuong”
print(name)
print_name()
print(name)
In this code, the print(name) function only executed successfully if the string
name exist inside the print_name() function because the scope of the string
name does not exist outside of the print_name() function.

8.
Python :
def average():
number = int(input(“Enter a number: “))
numbers = []
while number != 0
numbers.append(number)
number = int(input(“Enter a number”))
average = sum(numbers) / len(numbers)
return average

C# :
9. In the same language, write the code you would need to call that function and
print out the result.
10. To the code from 9, add code to print the message “Double digits” if the
average is above or equal to 10. Otherwise, print the message “Single digits”.
Provide a screenshot of your program running.

You might also like