Partial preview of the text
Download Computer science for class 11 ch#3 python notes and more Study notes Computer science in PDF only on Docsity!
me, CHAPTER-3: Programming FundamentalsCLASS ~ XI COMPUTER PROGRAM A set of well-define instructions which a computer can execute to solve a problem is known as computer Program. PROGRAM EXECUTION Program file store in disk memory. Program is loaded into main memory at the time of execution. One instruction fetched at a time and provide to CPU for execution. Program and data both are operate in a same main memory for faster execution. - Yes Disk Memory Service Interrupt Secondary Memory OperatingSystem Loads Program Into RAM GD fo2 Instruction . [3 Instructio age 4. Instruction. “4 id: 4 5 _ Instruction. d a 6 (instruction. J Program Is Set Of Instructions Stored In The MainMemory RAM Primary Memory ~ Main Memory RAM PROGRAMMING LANGUAGE Programming Language is a set of instruction written by a programmer to deliver instructions to computer | to perform task. Each language has its own keyword and syntax. Programmer write instructions by using these keywords also known as code. Programming language are divided into two parts: w High Level Programming Language. mw Low Level Programming Language. LOW LEVEL PROGRAMMING LANGUAGE Difficult to understand and not human friendly. Hard to debug and find errors. Memory efficient and faster to execute. Only runs on specific platforms. HIGH LEVEL PROGRAMMING LANGUAGE Easy to understand and human friendly. Easy to debug and find errors. Not Memory efficient and slower to execute. Run on any platform. COMPILER Compiler are used to convert source/high-level code into machine code. de, compiler checks the syntax and throw an error if anything is not following the When you compile your co tules, Compiler translate the whole code at a time. INTERPRETER interpreter are used to directly executes the instruction without concerting into machine code. Scanned with | CamScanner’: CHAPTER-3: Programming FundamentalsCLASS — XI ing is not following the When you compile your code, compiler checks the syntax and throw an error if anything !s no’ tules. An interpreter translates only one statement at atime. enENNECOM LE INTERPRETER! It translates source code line by line It Complies whole source code at a time It is slower It is faster It consumes more time It consumes less time It is more efficient It is less efficient It is larger in size Itis smaller in size ¢ _ How Compiler Works N "Compiler i Machine Code Output” : a / sf] Source Code © guru99.com How Interpreter Works [ETT a] f \ 4 : | BEBE i figures Source Code Interpreter ar Output = 4 sd / See PYTHON Python is one of the most famous, high-level programming language. It was first introduced in 1992 by Guide-van Rossum. ; APPLICATION OF PYTHON It Is use for Data Science, Data Analytics. Itis use for Machine Learning. Itis use for Web Development, Software Development. It is use for Artificial Intelligence (Al), Robotics. ADVANTAGES OF PYTHON It is high-level programming language which Is very human friendly. Its syntax is similar to English which makes It easy to understand. It is open source means many of the resources are available free of cost. It has many libraries and frame works which makes it easier for programmer to work. Scanned with | CamScanner’: CHAPTER-3: Programming FundamentalsCLASS ~ XI — hae Pensize Wicth Sets:the-width-of-the pen for drawing penup None Picks up the turtles tail so that it doesn’t draw when it moves Pendown a Puts down the turtles tail so that it draws when it moves goto XY Moves the turtle to position x,y color Color name Sets the color for drawing. Use ‘red’, ‘black’, etc backward() Distance (in Moves the Turtle object by the specified number of pixels in pixels) the backward direction TURTLE PROGRAM TO PRINT SQUARE Following is a code to print a square with turtle: import turtle s = turtle.Turtle() OUTPUT: for i in range(4): s.forward(50) s.right(90) turtle.done() EXPLAINATION OF CODE import turtle ; This line imports the Turtle graphics module. - §=turtle.Turtle() : Here, we are creating a new turtle object called s. This turtle object s represents the pen or the turtle" on the screen that will be used to draw shapes. for i in range(4): : This is a for loop that will run 4 times. The range(4) function generates a sequence of numbers from 0 to 3, so the loop will iterate four times. Each iteration represents drawing one side of the square. s.forward(50) : This command moves the turtle s forward by 50 units (pixels) in the direction it is currently facing. ne s.right(90) : This command turns the turtle s to the right by 90 degrees. Since a square has four sides with right angles, the turtle needs to turn 90 degrees after drawing each side. In loop, the turtle moves forward by 50 units and then turns right by 90 degrees. This process repeats four times. turtle.done() : This function tells the turtle graphics program that we're done with our drawing. It is generally used to keep the turtle graphics window open until the user closes it. Without this line, the window might close immediately after the drawing is completed. TURTLE PROGRAM TO PRINT TWO CIRCLES Following is a code to print two circles with turtle: import turtle turtle.Screen() turtle.screensize(200,150,"White") OUTPUT: turtle.dot(10,"Blue") turtle.circle(50) turtle.pencolor("Black") turtle.circle(-50) turtle.done() EXPLAINATION OF CODE import turtle : This line imports the Turtle graphics module. turtle.Screen() : This command initializes a window or screen for turtle graphics. This window is where ; Scanned with | CamScanner’: