PROGRAMMING WITH ENIAC BINARY CODES LOW LEVEL HIGH LEVEL LANGUAGES PYTHON DRAWING DRAWING WITH CONDITIONALS ITERATIONS LOOPS LISTS FUNCTIONS BIG O CS100 PROFESSOR SULTANA GMU CS Dept Slides Adapted from Dr Zaman Agenda Lecture Any Last Minute Questions Mini Exam 1 Harvard Mark 1 1944 Remember this Computer First computer to write programs for This Photo by Unknown Author is licensed under CC BY Programming the ENIAC 1945 Programming meant rewiring Grace Hopper The most damaging phrase in the language is It s always been done that way Grace Hopper One of the first programmers of the Harvard Mark 1 Coined the term bug Built the first compiler in 1952 which transformed source code in a programming language and converted to machine language Compiler abstracts the low level and unnecessary complexity of machine language Her compiler wasn t widely used Wasn t taken seriously As a result Fortran IBM 1957 dominated early computer programming Fortran IBM sold computers and created Fortran to compile only on IBM computers Only ran on single type of computer IBM The code had to be rewritten if you upgrade the computer Computer Experts formed a Consortium in 1959 advised by Grace Hopper to produce a common language used across different machines The result was Cobol No matter what computer is used the language worked write once run anywhere this is true for all programming languages today Languages 1960s Algol Lisp Basic 1970s Pascal C 1980s C Objective C Perl 1990s Python Ruby Java Millennium Swift C Chances are your browser was created using C or Objective C Binary Computer Codes Primitive Operations Each capability of a device is given some code in bits For example let s say ADD 0001 SUB 0010 and MUL 0011 Registers Registers are a computer s scratch work space Each one has a code For example let s say REGISTER0 0000 REGISTER1 0001 etc Machine instructions Each full instruction is based on definitions like those above Example ADD REGISTER0 to REGISTER1 and store the result in REGISTER3 0001 0000 0001 0011 ADD REGISTER0 REGISTER1 REGISTER3 Higher Level Languages Programming in binary would be a nightmare Programming in assembly the human readable equivalent of binary is feasible in some limited cases but otherwise would still be a mess Assembly Language is Low Level Fortunately we also have a number of high level languages The idea of high level languages and their place hasn t changed much as we can see from this 1983 video titled Bits and Bytes episode 6 The main difference today is the choice of languages which are popular for example Python C C Java JavaScript etc Let s Play https studio code org s 20 hour stage 9 puzzle 1 11 Levels Python Overview Python is a programming language and an environment It is a high level language Frequently used in professional settings e g Google Turtles then For some the first computer programming experience is drawing with a turtle Drawing with turtles is a form of programming this fact isn t always acknowledged The classical turtle drawing language is called Logo Source UMBC Turtles today We will do our programming in a language called Python Python includes built in turtle graphics capabilities Described extensively in the How to Think Like a Computer Scientist Learning with Python 3 online textbook starting from Chapter 3 The first two chapters give an overview of basic programming concepts in Python like numbers strings and variables Don t forget to read those chapters Make sure you have Python and Geany Installed Install Python o Go to https www python org downloads o Download the installer for version 3 12 for your machine o Install by executing the installer Install Geany o Go to https www geany org download releases o Download the installer for version 2 0 for your machine o Install by executing the installer Agenda Exam 1 Discussion Lecture CP 6 Install VSCode https code visualstudio com download Running Python Code on Geany Make sure you save the file with py extension Example Create a new file program py Type your code in Run your code by clicking the run button in the toolbar Mac Users only if using Geany If you are using Mac and running python code for the first time in Geany Save your file From the menu go to Build Set Build Commands and change python to python3 in the boxes next to Compile and Execute Make sure you have a space after python3 Only need to do this the first time the setting will be saved for future python programs Only for Mac users Do not do this if you are a windows user Running Python Code on VSCode Create a new file programname py Make sure you save the file with py extension Example Type your code in and save file ctrl s command s Run your code in the terminal oType in python3 programname py More Practice with Print CP 6 submit your helloworld py file More Practice with Print CP 6 submit your helloworld py file More Practice with Print CP 6 submit your helloworld py file More Practice with Print CP 6 submit your helloworld py file Agenda Class Participation 7 Lecture Class Participation 7 1 Create a classparticipation7 py 2 Print 3 statements o Given How would you print I am currently in Fairfax Virginia o Using f string formatting Write a print statement to output I like to eat an apple and a banana o Given How would you print I have these pets cat dog hamster The programming process 1 Think about the problem 2 Write down a series of instructions which might solve the problem 3 Ask the computer to execute the instructions Examine the results 4 5 If we re happy with the results then we are done 6 Otherwise rethink the instructions and modify them Then go back to step 3 Let s write our own useful program Decimal to Binary o Dec2bin py We want to divide the number until we get to zero o Need to use a while loop division and a way to find the remainder Common Python Instructions print hello x 10 if x 5 print some text assign a value to a variable check a condition print x is greater than five print x is less than or equal to five if x 2 0 use the remainder to check even odd else else print x is even print x is odd for i in range 4 repeat over a range i 0 1 2 3 print number str i str function converts to string Turtle Instructions import turtle imports the library and everything we need wn turtle Screen Set up the window and its attributes wn bgcolor lightgreen Set up the window s background color wn title My First Program Set up the window title bar alex turtle Turtle Create alex the turtle alex forward 50 use alex to
View Full Document