0% found this document useful (0 votes)
19 views

Unit7.1 Block It All Outmoving From Blocks To Text

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Unit7.1 Block It All Outmoving From Blocks To Text

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Unit7.

1
Block it all out :Moving from blocks to text
Scratch Programs:
1. To add two numbers:

2. To subtract two numbers

3. To multiply two numbers


4. To divide two numbers

5. To find Area of a square

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

IDLE: Integrated Development and Learning Environment


Execute means running a program.

Write about the two working environments in python.

Text based programming environments

Script mode Interactive mode

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 ")

Assignment: History of Python: (Research)


Who developed Python programming language?-Why is python so popular?
-How is python used? What can Python do? Why Python?

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

Variable: Variables are containers for storing data values.

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:

Reserve word of the compiler/interpreter which can’t be used as identifier

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy