Unit7.1 Block It All Outmoving From Blocks To Text
Unit7.1 Block It All Outmoving From Blocks To Text
1
Block it all out :Moving from blocks to text
Scratch Programs:
1. To add two numbers:
HW:
6. Area of triangle
7. Perimeter of a rectangle
8. Average of the three numbers
Block based programming: Programming using drag and drop blocks.
Ex: Scratch
Text based Programming: Programming that requires the programmer to type text.
Ex: python
Script Mode, is used when the user is working with more than one single code or a block of code. In
script mode we can create a program, save a program, run a program, correct errors,open a
program and add comments.
Interactive mode is used when an user wants to run one single line or one block of code.
To close python type, exit().
Print Statement: the print statement is a python command that outputs information onto the
screen. Python is case sensitive language so can tell the difference between upper case (Capital)
and lower case(Small) letters.
# Program 1
print("Hello, World!")
Output:
Hello, World!
# Program 2
print("Reqelford international School”)
print("Reqelford international School ")
print("Reqelford international School ")
Python Comments
Comments can be used to explain Python code.
Comments can be used to make the code more readable.
Comments can be used to prevent execution when testing code.
Creating a Comment
1. Comments starts with a #, and Python will ignore them:
#This is a comment.
print("Hello, World!")
2. Comments can be placed at the end of a line, and Python will ignore the rest of the line:
print("Hello, World!") #This is a comment
3. A comment does not have to be text that explains the code, it can also be used to prevent
Python from executing code:
#print("Hello, World!")
print("How are you!")
HW: Practice in Pg 17
Identifiers:
A Python identifier is a name used to identify a variable, function, class, module or other object.
* An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more
letters, underscores and digits (0 to 9).
* Python does not allow special characters
* Identifier must not be a keyword of Python.
* Python is a case sensitive programming language.
Thus, Rollnumber and rollnumber are two different identifiers in Python.
Some valid identifiers : Mybook, file123, z2td, date_2, _no
Some invalid identifier : 2rno,break,my.book,data-cs
Some additional naming conventions
1. Class names start with an uppercase letter. All other identifiers start with a lowercase letter.
2. Starting an identifier with a single leading underscore indicates that the identifier is private.
3. Starting an identifier with two leading underscores indicates a strong private identifier.
4. If the identifier also ends with two trailing underscores, the identifier is a language-defined
special name.
Keywords in python:
Input statement: The input() function allows user input. The input function
captures users input as a string function.
Ex:-1
x = input('Enter your name:')
print('Hello,', x)
Ex:-2
k=int(input(“enter a value:”)
s=k+1
print(s)
Data Types:
Data Type specifies which type of value a variable can store.
Casting: The process of ensuring data is set to the correct data type.
Ex: num1=input(“enter a number”)
answer=num1*5
Print(answer)
Ouput:=
Enter a number: 7
77777
If you cast the input to an integer:
num1=int(input(“enter a number”))
answer=num1*5
print(answer)
Ouput:=
Enter a number: 7
35