3
Lesson: Screen Output Screen output displaying characters on the screen (numbers, letters, special characters, spaces etc) formatting the information eg. tabs, line breaks, number of decimal points etc. Displaying literal strings: a literal string is a series of characters in quotes examples: Code Output Notes put^”Hellothere^bobb y251!” Hellothere^bobby 251! literal duplication put^”The^answer^is:^ ^” The^answer^is:^^ non letters ie “:” put^”abc”:10 abc^^^^^^^ field width put ^”\tThe^answer\ nis:” ^^^^^^^^^^The^an swer is: control characters (\) Notes: the string is duplicated literally ie. 1 space = 1 space, no space = no space; what you see is what you get. notice quotes are not output notice that numbers and non-letters can be part of the string control characters eg \t, \n,\\ can be used for formatting field width calculation: number of spaces = field width – length of string strings are left aligned within fieldwidth Exercise: What will the output be for the following code? Code Output Notes put^“yabba^^^”.. put^“dabba” put^“yes\n\nmam” put^“String output is Note: ^ indicates a space – don’t type this. Page 1

02_ScreenOutput

  • Upload
    ruby-li

  • View
    220

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 02_ScreenOutput

Lesson: Screen Output

Screen output displaying characters on the screen (numbers, letters, special characters, spaces etc) formatting the information eg. tabs, line breaks, number of decimal points etc.

Displaying literal strings: a literal string is a series of characters in quotes

examples:Code Output Notesput^”Hellothere^bobby251!” Hellothere^bobby251! literal duplicationput^”The^answer^is:^^” The^answer^is:^^ non letters ie “:”put^”abc”:10 abc^^^^^^^ field widthput ^”\tThe^answer\nis:” ^^^^^^^^^^The^answer

is:control characters (\)

Notes: the string is duplicated literally ie. 1 space = 1 space, no space = no space; what you see is what you get. notice quotes are not output notice that numbers and non-letters can be part of the string control characters eg \t, \n,\\ can be used for formatting field width calculation: number of spaces = field width – length of string strings are left aligned within fieldwidth

Exercise: What will the output be for the following code?

Code Output Notesput^“yabba^^^”..put^“dabba” put^“yes\n\nmam”put^“String output is fun..”:25put^”\\\\\\n2+3”

Displaying numbers and numeric expressions

examples:Code Output Notesput^5 5 Integersput^25 25 Integersput^34.789 34.789 Realput^4*3 12 Evaluates expression and prints answerput^8+2-3 7 Evaluates expression and prints answerput^38.4:10:2 ^^^^^38.40 field width and number of decimalsput^5:4:1 ^5.0put^546.23:2:1 546.2 rounds off; ignores field width (too small)Notes:

Note: ^ indicates a space – don’t type this. Page 1

Page 2: 02_ScreenOutput

Lesson: Screen Output

a number and numeric expression is evaluated not duplicated field width: spaces = fieldwidth - number of characters including decimals numbers are right aligned within field width if field width is too small, it is ignored

Exercise:What will the output be for the following code?

Code Output Notesput^55.6put^39.2:7:3put^85:1:6put^8+6+9-2

55.6^39.20085.00000021

Displaying a combination of informationTo combine different types of info in one print statement - use a comma

examples:

Code Output Notesput^5,”85”,24.2:3:1,”\n5*2” 58524.2

5*2put “8*8=^“,8*8 8*8=^64

notice:

RepeatHere’s a trick for repeating strings:

Code Output Notesput repeat(“abc”, 3) Abcabcabc string abc repeated 3 timesput repeat(“^”,10),”*” ^^^^^^^^^^*

Preventing automatic Carriage returnA double period (..) after a put statement will prevent an automatic carriage return.Example:put “abc”.. put “def”

Outputabcdef

Note: ^ indicates a space – don’t type this. Page 2

Page 3: 02_ScreenOutput

Lesson: Screen Output

Note: ^ indicates a space – don’t type this. Page 3