Chapter 13 Programming and Data Representation Flashcards
What is python?
Python is a multi-paradigm programming language
Key characteristics of python.
Keywords are written in lower case
Python is case sensitive meaning Number1 <> NUMBER1
What is VB.NET?
VB.NET is a multi paradigm, high-level programming language, implemented on the .NET Framework.
Key characteristics of VB.NET.
Every statement should be on a separate line. However, if necessary statements can be typed on the same line with a colon as a separator
Indentation is a good practice
Not case sensitive
Programs need to be compiled
What is Pascal?
Pascal is a multi-paradigm programming language
Key characteristics of Pascal.
Every statement must end in a semicolon (;)
Indentation is a good practice
Not case sensitive
Programs need to be compiled
Compound statements consists of a sequence of statements enclosed between the keywords begin and end
How to declare variables in python, VB.NET and Pascal?
- Python does not have variable declaration
- VB.NET Dim [, identifier] As
- Pascal var [, identifier] : ;
How to declare and assign values to constants in python, VB.NET and Pascal?
- Python =
- VB.NET Const =
- Pascal Const = ;
What is the difference between a variable and a constant?
A constants value should not be changed and a variables name can be changed if so desired.
How to assign values to a variable in python, VB.NET and Pascal?
- Python =
- VB.NET =
- Pascal := ;
Which are the arithmetic operators are different in pseudocode, python, VB.NET and Pascal?
Exponent: - Python: ^ - Integer division: ** - CB.NET: ^ - Pseudocode: Not available Integer division: - Python: DIV - Integer division: // - CB.NET\ - Pseudocode: Div Modulus: - Python: MOD - Integer division: % - CB.NET: Mod - Pseudocode: Mod
What do the rules of precedence define?
The Rules of precedence define the order of the calculations to be performed
How to output information on the screen in python, VB.NET and Pascal?
- Python print() (Moves to next list)
print(, end = ‘ ‘) (To avioid moving onto the next line after the output) - VB.NET Console.WriteLine()
Console.Write() (To avoid moving to the next line) - Pascal WriteLn()
Write() (To avoid moving to the next line)
How to get an input from the user in python, VB.NET and Pascal?
- Python A = input(‘Prompt: ‘)
- VB.NET Console.Write(‘Prompt: ‘)
A = Console.ReadLine () - Pascal Write(‘Prompt: ‘)
How to add comments in python, VB.NET and Pascal?
- Python # this is a comment
- VB.NET // this is a comment
- Pascal // this is a comment
// this is another comment
{this is a multi-line comment if more comments have to be written}
How are whole signed numbers assigned in python, VB.NET and Pascal?
- Python int
- VB.NET Integer
- Pascal Integer
How are signed numbers with a decimal point assigned in python, VB.NET and Pascal?
- Python Not available
- VB.NET Char
- Pascal Char
How are strings assigned in python, VB.NET and Pascal?
- Python str
- VB.NET String
- Pascal String
How to write booleans in python, VB.NET and Pascal?
- Python bool
- VB.NET Boolean
- Pascal Boolean
How are Monetary values assigned in python, VB.NET and Pascal?
- Python Not available
- VB.NET Decimal
- Pascal Currency
How are date values assigned in python, VB.NET and Pascal?
- Python Not available as a built-in data type
- VB.NET Date
- Pascal TDateTime
How to write equal in python, VB.NET and Pascal?
- Python ==
- VB.NET =
- Pascal =
How to write not equal in python, VB.NET and Pascal?
- Python !=
- VB.NET <>
- Pascal <>
How to write greater than in python, VB.NET and Pascal?
- Python >
- VB.NET >
- Pascal >
How to write less than in python, VB.NET and Pascal?
- Python <
- VB.NET <
- Pascal
How to write greater than or equal to in python, VB.NET and Pascal?
- Python >=
- VB.NET >=
- Pascal >=
How to write less than or equal to in python, VB.NET and Pascal?
- Python <=
- VB.NET <=
- Pascal <=
How to write AND in python, VB.NET and Pascal?
- Python and
- VB.NET And
- Pascal AND
How to write OR in python, VB.NET and Pascal?
- Python or
- VB.NET Or
- Pascal OR
How to write NOT in python, VB.NET and Pascal?
- Python not
- VB.NET Not
- Pascal NOT
How to write an IF…THEN statement in python, VB.NET and Pascal?
- Python if:
- VB.NET If Then
End If
- Pascal if :
then
How to write an IF…THEN statement in python, VB.NET and Pascal?
- Python if:
else:
- VB.NET If Then
Else: End If
- Pascal if:
thenelse:
How to write an IF…THEN statement in python, VB.NET and Pascal?
- Python if:
elif: else:
- VB.NET If Then
Elseif: Else: End If
- Pascal if:
thenelse: if then else:
How to write a CASE statement in VB.NET and Pascal?
- VB.NET Select Case
Case value1Case value1, value2 Case value4 TO value5 . . . CaseElse
End Select - Pascal case of value1: value1, value2 value4..value5 . . . else
end;
How to iterate in Python, VB.NET and Pascal?
- Python:
for in range(s, e, i): - VB.NET:
For = s To e Step i
Next
- Pascal:
for := s to e do
;
How to write a Post-condition statement in Python, VB.NET and Pascal?
- Python: not available
- VB.NET:
Do
Loop Until - Pascal: repeat ; until ;
How to write a Pre-condition statement in Python, VB.NET and Pascal?
- Python:
while : - VB.NET:
Do While
Loop
Do Until
Loop
- Pascal:
while do
;
How to declare arrays in Python, VB.NET and Pascal?
- Python doesn't have arrays. The equivalent is called list and the data entered in a list doesn't have to be of the same data type because python's lists are dynamic. Example: List1 = [] List1.append("Fred") List1.append("#Jamie23") -VB:NET: Dim () As - Pascal var : array[lowerBound..upperBound] of ;
How to access a 1D array in Python, VB.NET and Pascal?
- Python: NList[24] = 0 - VB.NET: NList[25] = 0 - Pascal: NList[24] := 0
How to create 2D arrays Python, in VB.NET and Pascal?
- Python ex.: Board = [[0 for i in range (7)] for j in range(6)] Board = [[0] * 7] * 6 - VB.NET: Dim (, ) As - Pascal: var : array[1uBound1..uBound1, 1uBound2..uBound2] of ;
How to access 2D arrays Python, in VB.NET and Pascal?
- Python: Board[2][3] = 0 - VB.NET: Board(3, 4) = 0 - Pascal: Board[3, 4] := 0
How to access a single character using position P in a string in Python, in VB.NET and Pascal?
- Python: ThisString [P] (Counts from 0) - VB.NET: ThisString (P) (Counts from 0) - Pascal: ThisString [P] (Counts from 1)
How to return the string character associated with the specified character code from a string in Python, in VB.NET and Pascal?
- Python: chr(i) - VB.NET: Chr(i) - Pascal: Chr(i)
How to return an integer value representing the character code of the specified character in Python, in VB.NET and Pascal?
- Python: ord(ch) - VB.NET: Asc(ch) - Pascal: Ord(ch)
How to return an integer that contains the number of characters in string s in Python, in VB.NET and Pascal?
- Python: len(S) - VB.NET: len(S) - Pascal: Len(S)
How to return an integer that contains the number of characters in string S in Python, in VB.NET and Pascal?
- Python: len(S) - VB.NET: len(S) - Pascal: Len(S)
How to return a substring of length L from the left of string S in Python, in VB.NET and Pascal?
- Python: S[0:L] - VB.NET: Left(S, L) - Pascal: LeftStr(S, L)
How to return a substring of length L from the right of string S in Python, in VB.NET and Pascal?
- Python: S[-L:] - VB.NET: Right(S, L) - Pascal: RightStr(S, L)
How to return a substring of length L from position P in string S in Python, in VB.NET and Pascal?
- Python: S[P : P + L] - VB.NET: mid(S, P, L) - Pascal: MidStr(S, P, L)
How to join strings in Python, in VB.NET and Pascal?
- Python: s = S1 + S2 - VB.NET: s = S1 + S2 s = S1 & S2 - Pascal: S := Concat (S1, S2); S := S1 + S2;
How to round up or down numbers in Python, in VB.NET and Pascal?
- Python: round(x, ndigits) - VB.NET: Math.Round(x) - Pascal: Round(x)
How to truncate numbers in Python, in VB.NET and Pascal?
- Python: int(x) - VB.NET: Math.Truncate(x) - Pascal: Trunc(x)
What does truncate number x mean?
Truncate number x means that the whole number part of the real number x is returned except the decimal point
How to convert a string to a number in Python, in VB.NET and Pascal?
- Python: int(S) - VB.NET: CInt(S) - Pascal: StrToInt(S)
How to output random numbers in Python, in VB.NET and Pascal?
- Python:
import random
value = random.randint(1, 6) print (value) - VB.NET: Dim RandomNumber As New Random Dim x As Integer x = RandomNumber.Next(1, 6) - Pascal: RandomRange (1, 6)