310 likes | 317 Views
Explore the basic concepts of advanced computer programming with Python, focusing on control structures, functions, scoping, and abstraction. Learn to write and understand algorithms using Python.
E N D
Advanced Computer Programming Sinan AYDINAnadolu Üniversitesi
Syllabus Advanced Computer Programming
Resources Advanced Computer Programming
Review of the BasicConcepts Review Computer Programming Phyton Control Structures Cycles Flow Diagrams
Computer Programming Functions, Scoping, Abstraction Programmers write instructions in various programming languages, some directly understandable by computers and others that require intermediate translation steps. Althoughhundreds of computer languages are in use today, the diverse offerings can be divided intothree general types: 1. Machine languages 2. Assembly languages 3. High-level languages
IntroductiontoPython Programming DisplayingText
IntroductiontoPython Programming DisplayingText
IntroductiontoPython Programming AddingIntegers Variablenamessuch as integer1, integer2 andsumactuallycorrespondtoPythonobjects. Everyobject has a type, a size, a valueand a location in thecomputer’smemory. A program cannotchange an object’stypeorlocation.
IntroductiontoPython Programming AddingIntegers
IntroductiontoPython Programming ArithmeticOperators
IntroductiontoPython Programming ArithmeticOperators
IntroductiontoPython Programming Equalityandrelationaloperators.
IntroductiontoPython Programming Equalityandrelationaloperators
IntroductiontoPython Programming Control Structures
IntroductiontoPython Programming IfSelectionStructre
IntroductiontoPython Programming IfSelectionStructre
IntroductiontoPython Programming IfSelectionStructre
IntroductiontoPython Programming whileRepetitionStructure
IntroductiontoPython Programming Formulating Algorithms: Case Study 1 (Counter-Controlled Repetition) A class of ten studentstook a quiz. Thegrades (integers in therange 0 –100) forthisquiz areavailable. Determinetheclassaverage on thequiz. Pseudocode algorithm that uses counter-controlled repetition to solve the class-average problem. Set total to zero Set grade counter to one While grade counter is less than or equal to ten Input the next grade Add the grade into the total Add one to the grade counter Set the class average to the total divided by ten Print the class average
IntroductiontoPython Programming Formulating Algorithms: Case Study 1 (Counter-Controlled Repetition) A class of ten studentstook a quiz. Thegrades (integers in therange 0 –100) forthisquiz areavailable. Determinetheclassaverage on thequiz. Pseudocode algorithm that uses counter-controlled repetition to solve the class-average problem. Set total to zero Set grade counter to one While grade counter is less than or equal to ten Input the next grade Add the grade into the total Add one to the grade counter Set the class average to the total divided by ten Print the class average total=0gradeCounter=1whilegradeCounter<=10:grade=input("Entergrade:")grade=int(grade) total=total+gradegradeCounter=gradeCounter+1average=total/10print("classaverage is", average)
IntroductiontoPython Programming Formulating Algorithms: Case Study 2(Counter-Controlled Repetition) A class of ten studentstook a quiz. Thegrades (integers in therange 0 –100) forthisquiz areavailable. Determinetheclassaverage on thequiz. Pseudocode algorithm that uses counter-controlled repetition to solve the class-average problem. Initialize total to zero Initialize counter to zero Input the first grade (possibly the sentinel) While the user has not as yet entered the sentinel Add this grade into the running total Add one to the grade counter Input the next grade (possibly the sentinel) If the counter is not equal to zero Set the average to the total divided by the counter Print the average else Print “No grades were entered”
IntroductiontoPython Programming Formulating Algorithms: Case Study 2(Counter-Controlled Repetition) A class of ten studentstook a quiz. Thegrades (integers in therange 0 –100) forthisquiz areavailable. Determinetheclassaverage on thequiz. Pseudocode algorithm that uses counter-controlled repetition to solve the class-average problem. Initialize total to zero Initialize counter to zero Input the first grade (possibly the sentinel) While the user has not as yet entered the sentinel Add this grade into the running total Add one to the grade counter Input the next grade (possibly the sentinel) If the counter is not equal to zero Set the average to the total divided by the counter Print the average else Print “No grades were entered”
IntroductiontoPython Programming Augmented Assignment Symbols Python provides several augmented assignment symbols for abbreviating assignment expressions. c = c + 3can be abbreviated with the augmented addition assignment symbol += as c += 3 variable = variable operator expression -- > variable operator= expression where operator is a binary operator, such as +, -, **, *, /, or %, can be written in the form
IntroductiontoPython Programming ForRepetitionStructure forcounter in range( 1, 101 ): forcounter in range( 100, 0, –1 ): forcounter in range( 7, 78, 7 ) forcounter in range( 99, -1, -11 ):
IntroductiontoPython Programming ForRepetitionStructure A person invests $1000 in a savings account yielding 5 percent interest. Assuming that all interest is left on deposit in the account, calculate and print the amount of money in the account at the end of each year for 10 years. Use the following formula for determining these amounts: a = p ( 1 + r ) n where p is the original amount invested (i.e., the principal), r is the annual interest rate, n is the number of years and a is the amount on deposit at the end of the nth year.
IntroductiontoPython Programming ForRepetitionStructure A person invests $1000 in a savings account yielding 5 percent interest. Assuming that all interest is left on deposit in the account, calculate and print the amount of money in the account at the end of each year for 10 years. Use the following formula for determining these amounts: a = p ( 1 + r ) n where p is the original amount invested (i.e., the principal), r is the annual interest rate, n is the number of years and a is the amount on deposit at the end of the nth year.
IntroductiontoPython Programming Break andcontinueStatements
IntroductiontoPython Programming Break andcontinueStatements
IntroductiontoPython Programming LogicalOperators
IntroductiontoPython Programming Structure Programming
IntroductiontoPython Programming Structure Programming Rules forFormingStructured Programs 1) Beginwiththesocalledsimplestflowchart (Fig. 3.34). 2) Anyrectangle (action) can be replacedbytworectangles (actions) in sequence. 3) Any rectangle (action) can be replaced by any control structure (sequence, if, if/else, if/elif/else, while or for). 4) Rules 2 and 3 can be applied as often as you like and in any order.