Search Header Logo
Input Function

Input Function

Assessment

Presentation

Computers

7th Grade

Practice Problem

Easy

Created by

M Dwedari

Used 11+ times

FREE Resource

16 Slides • 23 Questions

1

Open Ended

What is syntax in programming language (3 minutes)?

2

Remember

Syntax is the rules of a programming language.

the arrangement of words and phrases to create well-formed sentences in a language. "the syntax of English"

In programming:

3

Multiple Choice

What is syntax in programming language?

1

Syntax is the word used to describe an error

2

Syntax is the rules of the programming language

3

It is used to read information

4

It is used to output information 

4

Python Programming

Input Function

By Mr. Dwedari

5

Input Function

  • The Input function reads a line from the console (keyboard).

  • The Input function converts all information that it receives into a string

Syntax :

variable = input("Type here a message for the user ")

6

Input Function

Example :

studentName=input("What is your name? ")

Remember, The Input function converts all information that it receives into a string

Syntax of Input Funtion:

variable = input("Type here a message for the user ")

7

Poll

Question image

Discuss in pairs then predict (1 minutes)

What does this code do?

Syntax error

Line 1: Asks a user for their name

Line 2: Displays the user entry in the shell

Line 1: Asks a user for their name

Line 2: Displays "name" in the shell

8

Test it in Thonny to find the correct answer (3-minutes)

media

9

Multiple Choice

Question image

Now, as you have tested it in Thonny

When the user had entered Kate what did this code display on the screen?

1

Kate

2

name

3

error

10

Open Ended

Question image

Use the code in the picture as a starting point to think how you can modify/change it to:

1- Ask the user for their first name and allow them to enter it

2- Ask the user for their last name and allow them to enter it

3- Display in the shell, the first name followed by the last name

(5 minutes)

Test your code in Thonny then copy your answer here.

Do not answer before you test it in Thonny

11

Multiple Choice

I have written three programs to answer the previous question

Remember, the program should:

1- Ask the user for their first name and allow them to enter it

2- Ask the user for their last name and allow them to enter it

3- Display in the shell, the first name followed by the last name.

Click the correct one

1
2
3

12

Open Ended

Question image

In Thonny, Modify the code shown to (2 minutes):

Display the message "Welcome" followed by the user's first name and last name

Copy your code from Thonny then paste it here

13

Solution

media

14

Poll

Question image

Predict ...

if the user enters for item1, 7

and for item2, 10

What will line 3 display?

The total amount is item1+item2

The total amount is 17

The total amount is 710

The total amount is 107

15

Test it in Thonny to find the correct answer (3-minutes)

media

16

Multiple Choice

Question image

Now, as you have tested it in Thonny

What has the code displayed in the shell when the user had entered 7 for item1

and for 10 item2?

1

The total amount is item1+item2

2

The total amount is 17

3

The total amount is 710

4

The total amount is 107

17

Casting

(Data-type conversion)

In programming, casting is used to convert data-type to a different one based on what it will be used for.

Remember ...

In programming, we can assign different types of data to variables and the choice of data type depends on the use of this variable.

18

Example

item = "crisp"

quantity = 5.2

print (quantity, item,"bags")

19

Example

item = "crisp"

quantity = 5.2

print (quantity, item,"bags")

The data type of the variable quantity is float because it is a decimal number

20

Multiple Choice

Question image

What will line 3 display?

1

quantity item bags

2

bags

3

5 crisp bags

4

5.2 crisp bags

21

Example

item = "crisp"

quantity = 5.2

print (quantity, item,"bags")

The data type of the variable quantity is float because it is a decimal number

quantity = int(quantity)

Converts the variable "quantity" from float to integer by deleting the numbers after the decimal point

Quantity of crisp bags can't have a decimal point so it is better to convert it to an integer:

22

Example

item = "crisp"

quantity = 5.2

quantity = int(quantity)

print (quantity, item,"bags")

Converts the variable quantity from float to integer by deleting the numbers after the decimal point

23

Poll

Question image

Predict ...

What will line 4 display?

5.0 crisp bags

5.2 crisp bags

5 crisp bags

quantity item bags

24

Test it in Thonny to find the correct answer (3-minutes)

media

25

Multiple Choice

Question image

Now, as you have tested it in Thonny

What did this code display on the screen?

1

5.0 crisp bags

2

5.2 crisp bags

3

5 crisp bags

4

quantity item bags

26

Casting Functions

​Casting Function

​ What it does?

​int ( )

​converts any value/variable between the bracket to Integer (whole number)

​float ( )

​converts any value/variable between the bracket to Float (a number with decimal point)

​str ( )

​converts any value/variable between the brackets to String

​bool ( )

​converts any value/variable between the brackets to Boolean

27

Fill in the Blank

Question image

What is the data type of the variable "answer" on line 1?

28

Fill in the Blank

Question image

What is the data type of the variable "answer" on line 2?

29

Fill in the Blank

Question image

What is the data type of the variable "amount" on line 1?

30

Fill in the Blank

Question image

What is the data type of the variable "amount" on line 2?

31

Fill in the Blank

Question image

What is the data type of the variable "amount" on line 2?

32

Fill in the Blank

Question image

What is the data type of the variable "price" on line 1?

33

Fill in the Blank

Question image

What is the data type of the variable "price" on line 2?

34

Poll

Question image

Discuss in pairs then predict ...

What will line 3 display?

6

6.0

price

"6"

price

35

Test it in Thonny to find the correct answer (3-minutes)

media

36

Multiple Choice

Question image

Now, as you have tested it in Thonny

What did this code display on the screen?

1

price

2

6

3

"6"

4

6.0

37

Poll

Question image

Discuss in pairs then predict ...

What will line 2 display?

Amount £1

Amount £1.25

Amount £price

Amount £1.00

38

Test it in Thonny to find the correct answer (3-minutes)

media

39

Multiple Choice

Question image

Now, as you have tested it in Thonny

What did this code display on the screen?

1

Amount £1

2

Amount £1.25

3

Amount £1.00

4

Amount £price

What is syntax in programming language (3 minutes)?

Show answer

Auto Play

Slide 1 / 39

OPEN ENDED