Page 110 - 2502_Pakistan-kifayat_C-8
P. 110

Scratch Code                                        Python Code



                                                         import time
                                                         def greet(name):
                                                             print("Hello" + name)
                                                             time.sleep(2)


                                                         # Equivalent of "when green flag clicked"

                                                         greet("Salman")
                                                         greet("Shahrukh")





                       Double Tap                                                    Century   #Technology Literacy
                                                                                       21 st
                                                                                      Skills  #Critical Thinking
                     State whether these statements are true or false.

                     1.  Visual programming requires strong syntax knowledge.

                     2.   Java can be used for web applications.
                     3.  Assembly language is close to machine language.

                     4.  Scratch is an example of textual programming.




                   WRITING SIMPLE PROGRAMS USING TEXTUAL LANGUAGES

              Writing simple programs using textual programming languages is the first step toward learning
              how to communicate with a computer using code. Textual languages like Python, C++, and Java use
              words, numbers, and symbols typed through a keyboard to give instructions. These languages allow
              programmers to write commands in a logical, step-by-step manner to solve problems or perform
              tasks.


                                                                 Hintbot


                                           Always check for indentation in Python. It helps the
                                         computer understand which lines of code belong to the
                                                             same block.


              Let us discuss some examples of programs using textual language (Python).

              Example 1: Adding Two Numbers

              a = 5
              b = 10




                  108  Premium Edition-VIII
   105   106   107   108   109   110   111   112   113   114   115