print input-presentation

45
Input and print in Python

Upload: martin-mcbride

Post on 13-Apr-2017

109 views

Category:

Education


0 download

TRANSCRIPT

Page 1: Print input-presentation

Input and printin Python

Page 2: Print input-presentation

Input strings and numbers

Printing different types of data

Simple formatting

Input prompt

Hello World!

Page 3: Print input-presentation

print()The print function displays

information to the user

Page 4: Print input-presentation

Code

Result

print('Hello World')

Page 5: Print input-presentation

Code

Result

print('Hello World')

print function displays the text

Page 6: Print input-presentation

Code

Result

print('Hello World')

Text included in quote marks

Page 7: Print input-presentation

Run the code

Page 8: Print input-presentation

Code

Result

print('Hello World')

Hello World

The print function displays the text

Page 9: Print input-presentation

Hello World!

Printing different types of data

Simple formatting

Input prompt

Input strings and numbers

Page 10: Print input-presentation

input()The input function accepts information from the user

Page 11: Print input-presentation

Code

Result

s = input('What day is it?')print(s)

Page 12: Print input-presentation

Code

Result

s = input('What day is it?')print(s)

input function gets information from the

user

Page 13: Print input-presentation

Code

Result

s = input('What day is it?')print(s)

This is the question (prompt) to ask the user

Page 14: Print input-presentation

Code

Result

s = input('What day is it?')print(s)

The response is stored in variable s

Page 15: Print input-presentation

Run the code

Page 16: Print input-presentation

Code

Result

s = input('What day is it?')print(s)

The input function displays the

prompt

What day is it?

Page 17: Print input-presentation

Code

Result

s = input('What day is it?')print(s)

The user types in a response

What day is it?Tuesday

Page 18: Print input-presentation

Code

Result

s = input('What day is it?')print(s)

The print function displays the result

What day is it?TuesdayTuesday

Page 19: Print input-presentation

Asking the user for a number

Page 20: Print input-presentation

Code

Result

s = input('What is the year?')y = int(s)print(y)

Page 21: Print input-presentation

Code

Result

s = input('What is the year?')y = int(s)print(y)

input function gets information from the

user

Page 22: Print input-presentation

Code

Result

s = input('What is the year?')y = int(s)print(y) The int function

converts the string s into a number y

Page 23: Print input-presentation

Run the code

Page 24: Print input-presentation

Code

Result

s = input('What is the year?')y = int(s)print(y) The input function

displays the prompt

What is the year?

Page 25: Print input-presentation

Code

Result

s = input('What is the year?')y = int(s)print(y)

User types in a string which represents a

number

What is the year?1066

Page 26: Print input-presentation

Code

Result

s = input('What is the year?')y = int(s)print(y) The int function

converts the string to a number

What is the year?10661066 print displays it

Page 27: Print input-presentation

Printing different types of data

Hello World!

Input strings and numbers

Simple formatting

Input prompt

Page 28: Print input-presentation

Code

Result

x = 'string data'print(x)

string data

Page 29: Print input-presentation

Code

Result

x = 2 + 3print(x)

5

Page 30: Print input-presentation

Code

Result

x = 0.5 * 3.0print(x)

1.5

Page 31: Print input-presentation

Code

Result

x = datetime.now()print(x)

2016-01-07 17:37:01.368503

Page 32: Print input-presentation

Hello World!

Input strings and numbers

Input prompt

Printing different types of data

Simple formatting

Page 33: Print input-presentation

Code

Result

print(1)print(2)print(3)

123

Each output starts on a new line

Several separate print

statements

Page 34: Print input-presentation

Code

Result

print('abc')print()print('def')

abc

def Blank line

Empty print statement

Page 35: Print input-presentation

Code

Result

print(1, 2, 3)

1 2 3Each item

separated by a space

Several items in one print statement

Page 36: Print input-presentation

Code

Result

print(1, 2, 3, sep='.')

1.2.3Each item

separated by a dot

Using the sep parameter

Page 37: Print input-presentation

Code

Result

print(1, 2, 3, sep='')

123 Items are not separated

Using the sep parameter with

and empty string

Page 38: Print input-presentation

s = 'abc'

empty = ''

Two quotes characters with no other characters

between them

Page 39: Print input-presentation

Code

Result

print(1, end='')print(2, end='')print(3)

123 Each item is printed on the same line

Using the end parameter

Page 40: Print input-presentation

Hello World!

Input strings and numbers

Simple formatting

Printing different types of data

Input prompt

Page 41: Print input-presentation

The input prompt doesn't have to be a question

Page 42: Print input-presentation

Code

Result

s = input('>')

>

Page 43: Print input-presentation

Code

Result

s = input()

Page 44: Print input-presentation

Code

Result

print('You are in the haunted library. There')print('is a book of spells on the table.')s = input()

You are in the haunted library. Thereis a book of spells on the table.

Page 45: Print input-presentation

schoolcoders.com@schoolcoders

Copyright Axlesoft Ltd 2015