General Functions
The following are basic functions that you will be expected to understand, explain, recognise in code, and use in pseudocode.
Input
Input is used to collect feedback from a user. For the purposes of this course, it will always refer to data entry via a keyboard, and therefore it will always result in a string variable.
C# string name = Console.ReadLine(); //This will read a line of text from the keyboard and store //it in a string variable called 'name' Python name = input() #This reads a line of text from the keyboard and stores it #as a string in a variable called 'name'
Open
Files represent an alternative data source to the keyboard. Often you will be expected to import data from a text file and process it in some manner. regardless of the language, the principles are the same:
- A file must be OPENED for reading
- Data is READ from the file
- Process repeats until you reach EOF (End Of File)
- File is CLOSED
In contrast to input, printing is the generic method for outputting data. Although data can be output to other destinations (files, printers etc) you are most likely to be displaying information on screen.
C# //In C# the output device is called the Console //You can either Write data (no newline added at the end) //or you can WriteLine (a newline is added at the end) //C# will accept any data type and automatically convert //it to string for this output bool b = false; int a = 15; string n = "Tom"; Console.WriteLine(b); //shows the text 'false' Console.WriteLine(a); //shows the number '15' Console.WriteLine(n); //shows the text 'Tom' Python #the print() function is used to display information on screen #Python requires all information to be converted to string format b = False a = 15 n = "Tom" print(str(b)) #prints 'False' print(str(a)) #prints the value '15' print(n) #prints 'Tom'; note as already string no conversion needed #printing without a newline print('This will not have a newline after it', end='') #by adding ,end='' within the print statement, you will override the #normal behaviour of adding a newline character