Variables, Input, and Output. Challenge: ● Ask the user his or her name, and repeat that name to...

13
Variables, Input, and Output

Transcript of Variables, Input, and Output. Challenge: ● Ask the user his or her name, and repeat that name to...

Page 1: Variables, Input, and Output. Challenge: ● Ask the user his or her name, and repeat that name to the user ● Pause video and try.

Variables, Input, and Output

Page 2: Variables, Input, and Output. Challenge: ● Ask the user his or her name, and repeat that name to the user ● Pause video and try.

Challenge:

● Ask the user his or her name, and repeat that name to the user

● Pause video and try

Page 3: Variables, Input, and Output. Challenge: ● Ask the user his or her name, and repeat that name to the user ● Pause video and try.

Input● Asks the user a question (input implies output!)

● Stores answer in a variable● You can't use input if you haven't created the variable

Page 4: Variables, Input, and Output. Challenge: ● Ask the user his or her name, and repeat that name to the user ● Pause video and try.

Input Requires

● A question● A variable to put answer in

Page 5: Variables, Input, and Output. Challenge: ● Ask the user his or her name, and repeat that name to the user ● Pause video and try.

Variable

● A place in memory to hold things

● Like a container● Different containers for different stuff

● Has a name

Page 6: Variables, Input, and Output. Challenge: ● Ask the user his or her name, and repeat that name to the user ● Pause video and try.

Variables require:

● Name – descriptive● Init – starting value● Type – kind of data (string, numeric)

● Purpose – or description

Page 7: Variables, Input, and Output. Challenge: ● Ask the user his or her name, and repeat that name to the user ● Pause video and try.

String Data● Text● Series of alphanumeric characters

● Usually enclosed in quotes (“”)

● Size depends on length of text

Page 8: Variables, Input, and Output. Challenge: ● Ask the user his or her name, and repeat that name to the user ● Pause video and try.

Numeric Data● Integer (+/-,0, no decimals)● Long Integer● Float (includes decimal values)● Double● Size depends on type of number

Page 9: Variables, Input, and Output. Challenge: ● Ask the user his or her name, and repeat that name to the user ● Pause video and try.

Challenge:● Ask the user his or her name.● Reply “Hello, <user>” Where <user> is the user name.

● Username should be incorporated into greeting

Page 10: Variables, Input, and Output. Challenge: ● Ask the user his or her name, and repeat that name to the user ● Pause video and try.

Sample Run

● Comp: what is your name?

● User: Marsha● Comp: Hi Marsha!● Pause video and try

Page 11: Variables, Input, and Output. Challenge: ● Ask the user his or her name, and repeat that name to the user ● Pause video and try.

String Concatenation● Technique for combining text● “a” + “b” = “ab”● Frequently uses the plus sign● Can be used to combine variables and literals:

● “Hi, “ + userName + “!”

Page 12: Variables, Input, and Output. Challenge: ● Ask the user his or her name, and repeat that name to the user ● Pause video and try.
Page 13: Variables, Input, and Output. Challenge: ● Ask the user his or her name, and repeat that name to the user ● Pause video and try.