Print input-presentation

Post on 13-Apr-2017

108 Views

Category:

Education

0 Downloads

Preview:

Click to see full reader

Transcript

Input and printin Python

Input strings and numbers

Printing different types of data

Simple formatting

Input prompt

Hello World!

print()The print function displays

information to the user

Code

Result

print('Hello World')

Code

Result

print('Hello World')

print function displays the text

Code

Result

print('Hello World')

Text included in quote marks

Run the code

Code

Result

print('Hello World')

Hello World

The print function displays the text

Hello World!

Printing different types of data

Simple formatting

Input prompt

Input strings and numbers

input()The input function accepts information from the user

Code

Result

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

Code

Result

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

input function gets information from the

user

Code

Result

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

This is the question (prompt) to ask the user

Code

Result

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

The response is stored in variable s

Run the code

Code

Result

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

The input function displays the

prompt

What day is it?

Code

Result

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

The user types in a response

What day is it?Tuesday

Code

Result

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

The print function displays the result

What day is it?TuesdayTuesday

Asking the user for a number

Code

Result

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

Code

Result

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

input function gets information from the

user

Code

Result

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

converts the string s into a number y

Run the code

Code

Result

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

displays the prompt

What is the year?

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

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

Printing different types of data

Hello World!

Input strings and numbers

Simple formatting

Input prompt

Code

Result

x = 'string data'print(x)

string data

Code

Result

x = 2 + 3print(x)

5

Code

Result

x = 0.5 * 3.0print(x)

1.5

Code

Result

x = datetime.now()print(x)

2016-01-07 17:37:01.368503

Hello World!

Input strings and numbers

Input prompt

Printing different types of data

Simple formatting

Code

Result

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

123

Each output starts on a new line

Several separate print

statements

Code

Result

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

abc

def Blank line

Empty print statement

Code

Result

print(1, 2, 3)

1 2 3Each item

separated by a space

Several items in one print statement

Code

Result

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

1.2.3Each item

separated by a dot

Using the sep parameter

Code

Result

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

123 Items are not separated

Using the sep parameter with

and empty string

s = 'abc'

empty = ''

Two quotes characters with no other characters

between them

Code

Result

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

123 Each item is printed on the same line

Using the end parameter

Hello World!

Input strings and numbers

Simple formatting

Printing different types of data

Input prompt

The input prompt doesn't have to be a question

Code

Result

s = input('>')

>

Code

Result

s = input()

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.

schoolcoders.com@schoolcoders

Copyright Axlesoft Ltd 2015

top related