
Input Function
Presentation
•
Computers
•
7th Grade
•
Practice Problem
•
Easy
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?
Syntax is the word used to describe an error
Syntax is the rules of the programming language
It is used to read information
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
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)
9
Multiple Choice
Now, as you have tested it in Thonny
When the user had entered Kate what did this code display on the screen?
Kate
name
error
10
Open Ended
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
12
Open Ended
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
14
Poll
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)
16
Multiple Choice
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?
The total amount is item1+item2
The total amount is 17
The total amount is 710
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
What will line 3 display?
quantity item bags
bags
5 crisp bags
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
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)
25
Multiple Choice
Now, as you have tested it in Thonny
What did this code display on the screen?
5.0 crisp bags
5.2 crisp bags
5 crisp bags
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 Blanks
Type answer...
28
Fill in the Blanks
Type answer...
29
Fill in the Blanks
Type answer...
30
Fill in the Blanks
Type answer...
31
Fill in the Blanks
Type answer...
32
Fill in the Blanks
Type answer...
33
Fill in the Blanks
Type answer...
34
Poll
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)
36
Multiple Choice
Now, as you have tested it in Thonny
What did this code display on the screen?
price
6
"6"
6.0
37
Poll
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)
39
Multiple Choice
Now, as you have tested it in Thonny
What did this code display on the screen?
Amount £1
Amount £1.25
Amount £1.00
Amount £price
What is syntax in programming language (3 minutes)?
Show answer
Auto Play
Slide 1 / 39
OPEN ENDED
Similar Resources on Wayground
32 questions
Multiplying and Dividing Integers
Presentation
•
7th Grade
34 questions
Chinese Philosophies - Confucianism, Taoism, Legalism
Presentation
•
7th Grade
34 questions
Plate Tectonics
Presentation
•
7th Grade
33 questions
Transformations on the Coordinate Plane
Presentation
•
7th Grade
35 questions
Physical Geography of Southeast Asia
Presentation
•
7th Grade
36 questions
Ecological Relationships
Presentation
•
7th Grade
36 questions
One-Step Equations with Rational Coefficients
Presentation
•
7th Grade
33 questions
L2 - Market Research
Presentation
•
7th Grade
Popular Resources on Wayground
6 questions
Secondary Safety Quiz
Presentation
•
9th - 12th Grade
10 questions
MyPath Diagnostic Overview
Presentation
•
6th - 8th Grade
20 questions
Lab Safety Quiz
Quiz
•
6th Grade
21 questions
Continents and Oceans
Quiz
•
6th Grade
20 questions
Adding and Subtracting Decimals
Quiz
•
5th Grade
20 questions
Parts of Speech
Quiz
•
5th Grade
16 questions
Subject & Predicate
Quiz
•
5th Grade
21 questions
Lab Safety
Quiz
•
10th Grade
Discover more resources for Computers
20 questions
Early Computing
Quiz
•
7th - 12th Grade
11 questions
Technology Acceptable Use
Quiz
•
6th - 8th Grade
16 questions
Clovis Unified Student Use of Technology
Quiz
•
4th - 8th Grade
10 questions
Exploring Computer Hardware and Software Components
Interactive video
•
6th - 10th Grade
16 questions
Responsible Use Guideline Quiz
Quiz
•
6th - 8th Grade
15 questions
Student Technology Agreement
Quiz
•
6th - 8th Grade
12 questions
What is Digital Citizenship
Quiz
•
7th Grade