0% found this document useful (0 votes)
9 views7 pages

Moving Block To Text

The document compares Scratch, a visual programming language for beginners, with Python, a text-based language used for more complex applications. It covers key programming concepts such as block-based vs text-based programming, GUI, syntax, and basic Python operations, including arithmetic and comparison operators. Additionally, it discusses Python programming basics, error handling, comments, variables, data types, flowcharts, conditional statements, and debugging techniques.

Uploaded by

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

Moving Block To Text

The document compares Scratch, a visual programming language for beginners, with Python, a text-based language used for more complex applications. It covers key programming concepts such as block-based vs text-based programming, GUI, syntax, and basic Python operations, including arithmetic and comparison operators. Additionally, it discusses Python programming basics, error handling, comments, variables, data types, flowcharts, conditional statements, and debugging techniques.

Uploaded by

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

Moving Block to Text

1. Scratch vs Python

● Scratch is a visual, block-based programming language often used for beginners,


especially in younger grades. It involves dragging and dropping blocks to create
programs, making it easier to understand the logic of programming without worrying
about syntax.
● Python, on the other hand, is a text-based programming language where you write
actual code. It is more flexible and widely used for real-world applications, as it allows for
more complex and powerful programs.

2. Block-based Programming vs Text-based Programming

● Block-based Programming (like Scratch) involves snapping blocks together to create


code. This is great for beginners because it removes syntax errors and focuses on logic.
● Text-based Programming (like Python) requires you to type out the commands (code).
It is more precise and offers greater control over your program, but it also requires
attention to detail in syntax.

3. Graphical User Interface (GUI) and Syntax

● A Graphical User Interface (GUI) in programming is the visual part of an application


that allows users to interact with the system through graphical icons and visual
indicators, rather than text-based commands.
● Syntax in programming refers to the rules that define the structure of valid statements in
a programming language. For example, in Python, the syntax for printing something is:

Python
print("Hello World")

4. Flowchart

● A Flowchart is a diagram that represents a process or algorithm. It uses different


shapes to represent various steps and decision points, making it a helpful tool in
planning and visualizing your program before writing the code.
5. Arithmetic Operators in Python

These operators perform mathematical operations:

● + : Addition
● - : Subtraction
● * : Multiplication
● / : Division
● // : Floor Division (returns an integer)
● % : Modulus (returns the remainder of division)
● ** : Exponentiation (raises a number to the power of another)

Example:

Python
a = 5
b = 2
print(a + b) # Output: 7

6. Comparison Operators in Python

These operators are used to compare values:

● == : Equal to
● != : Not equal to
● > : Greater than
● < : Less than
● >= : Greater than or equal to
● <= : Less than or equal to

Example:

Python
a = 5
b = 2
print(a > b) # Output: True
7. Python Programming Basics

IDLE

● IDLE (Integrated Development and Learning Environment) is a simple editor for writing
Python programs.
● IDLE converts your Python code to machine language, which the computer can
understand and execute.

Interactive Mode

● In Interactive Mode, you type commands one at a time directly into the Python shell (the
>>> prompt). It is useful for testing small bits of code.

● Example:

Python
>>> print("Hello World")
Hello World


Disadvantage: It cannot save your work.

Script Mode

● In Script Mode, you write your program in a text editor and save it with a .py extension.
You can run multiple commands at once.
● Example:

Python
# Save this as my_program.py
print("Hello World")
print("Python is fun!")

How to Enter Script Mode from Interactive Mode?


● To switch from Interactive Mode to Script Mode, you need to open a text editor (like
IDLE or other Python editors) and write the code there. Save it with the .py extension.

How to Run Program in Script Mode?

● After writing the program in Script Mode and saving it, you can run it using IDLE or the
terminal/command line:
1. Open your Python editor.
2. Write your code and save it as my_program.py.
3. In IDLE, click Run > Run Module or press F5.
4. If using terminal, type:

Unset
python my_program.py

8. Important Python Commands

● print(): Displays output on the screen.

Python
print("This is beautiful")


help(): Provides information about a function or module.

Python
help(print)


exit(): Exits the Python shell.

Python
exit()

Calculation without print: You can perform calculations without using the print()
function in the Interactive mode, but you need print() to display the result.

9. Error Handling and Debugging

● If your code has an error, everything may show up in red when you run the program.
● Common errors include missing parentheses, incorrect syntax, or using a wrong name.
● Correction can be done in the text editor where you write the code.

10. Comments in Code

● You can add comments in your Python code using the # symbol. Comments are
ignored by Python and are used to explain the code for others or for yourself.

Python
# This is a comment
print("Hello World") # This prints Hello World

11. Variables

● Variables store information that can be used later in the program.

Python
name = "John"
age = 12


User Input: To take input from the user, use the input() function:
Python
name = input("Enter your name: ")
print("Hello, " + name)

12. Data Types

● String: Text data. Default type for any data enclosed in quotes.

Python
name = "John"


Integer: Whole numbers. Use int() to convert.

Python
age = int(input("Enter your age: "))


Float: Decimal numbers. Use float() to convert.

Python
price = float(input("Enter price: "))

Casting

● Casting is the process of converting one data type to another.

Python
age = int("25") # String "25" is cast to an integer
13. Flowchart and Algorithm

● A Flowchart helps in planning the program’s logic.


● An Algorithm is a step-by-step procedure to solve a problem. It can be visualized using
a flowchart.

14. Conditional Statements

● If-Else Statement: Used for decision-making.

Python
age = 12
if age >= 18:
print("You are an adult.")
else:
print("You are a minor.")

15. Debugging Errors in Programs

● Common errors in Python include:


○ Syntax errors (e.g., missing parentheses, incorrect indentation).
○ Runtime errors (e.g., dividing by zero).
○ Logical errors (e.g., wrong output due to incorrect logic).

Use debugging techniques like reading error messages carefully and checking each line of code
to find and fix the error.

Important things to remember

1. Python used BIDMAS for calculation


2. Python is case sensitive.
Eg: Print (“hi”) will show error because p in Print should be small.
3. Text requires “ “ but numbers don’t

You might also like