1 / 9

Computer Programming

Computer Programming. Week 2. Learning Objective: To understand what =variables are To be able to use = to assign variables To be able to use the FUNCTIONS: print & input. Remember from last week, there are 2 modes that you can program with in PYTHON…. INTERACTIVE Mode

vaughan
Télécharger la présentation

Computer Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer Programming Week 2 • Learning Objective: • To understand what =variables are • To be able to use = to assign variables • To be able to use the FUNCTIONS: print & input

  2. Remember from last week, there are 2 modes that you can program with in PYTHON… INTERACTIVE Mode >>> (has chevrons) SCRIPT Mode Used for writing larger programs and requires F5 to run.

  3. Open PYTHON and go to SCRIPT Mode (Go to FILE menu, then click New Window) • Write the following code into your PYTHON window • and save it as InteractiveProgram.py print("Please type your name in") my_name = input () What is the purpose of my_nameinthis program?

  4. Variable A variable is a place in the computer’s memory that holds a temporary value. Data We can place data into a variable by ASSIGNING it to the variable. Assignment Variable_Name Data In Python, it looks like this Name = ‘Tom’

  5. print("Please type your name in") my_name = input () input () is a useful function that prompts the user to enter some data. It means that whatever the user types in will be ASSIGNED to the variable my_name Save & Run the program (F5) to test it.

  6. Edit your program and add the bottom line of code… print("Please type your name in") my_name = input () print(“Nice to meet you” ,my_name) Python allows us to print a bunch of letters (known as a string) followed by a variable! BUT! Make sure you separate the two things with a coma! Re-test the program by running it.

  7. Edit your program further by adding the last three lines of code. Save it and then Run it (F5) print("Please type your name in") my_name = input () print("Nice to meet you ", my_name) print("So ", my_name , " what is your favourite food?") favourite_food = input () print("Ah, your favourite food is " , favourite_food) How does this program work?

  8. Edit your program further by adding the last three lines of code. Save it and then Run it (F5) print("Please type your name in") my_name = input () print("Nice to meet you ", my_name) print("So ", my_name, " what is your favourite food?") favourite_food = input () print("Ah, your favourite food is " , favourite_food) QUESTIONS … you have 2 minutes! (Teacher > Click slide to start timer) Write down the name of a variable used in the above program How many variables are used in the above program What kind of character/symbol is used to assign values to a variable Write down an example of assignment Katie is writing her first program. It won’t run properly. Can you spot the Syntax error? End 1:49 1:50 1:51 1:52 1:53 1:54 1:56 1:48 1:57 1:58 1:59 1:31 1:55 1:47 1:45 1:32 1:33 1:46 1:35 1:36 1:37 1:38 1:34 1:40 1:41 1:42 1:43 1:39 1:02 1:00 1:44 1:29 1:30 2:00 1:27 1:26 1:25 1:24 1:23 1:22 1:21 1:20 1:19 1:18 1:17 1:16 1:28 1:14 1:03 1:01 1:04 1:05 1:15 1:07 1:06 1:09 1:10 1:11 1:12 1:13 1:08 0:48 0:31 0:50 0:51 0:57 0:53 0:54 0:55 0:56 0:58 0:52 0:49 0:36 0:33 0:34 0:35 0:47 0:38 0:40 0:41 0:42 0:43 0:44 0:39 0:59 0:45 0:46 0:32 0:14 0:30 0:19 0:20 0:21 0:22 0:25 0:24 0:26 0:27 0:18 0:28 0:23 0:37 0:11 0:17 0:13 0:12 0:29 0:10 0:09 0:08 0:07 0:06 0:05 0:04 0:03 0:16 0:15 0:01 0:02 Print(‘Hello World’)

  9. If you can, do all these programs in SCRIPT mode (i.e. go to FILE, NEW WINDOW…then press F5 to run) Task: Create a program in python that prompts the user for their name AND the names of their top 5 favourite films. Each film should be assigned to a separate variable. When run, the computer should output the following… Hello [my_name], your top 5 favourite films are as follows: [favourite_film1] [favourite_film2] [favourite_film3] [favourite_film4] [favourite_film5] Here is an example Hello Tim, your top 5 favourite films are as follows: The Thin Red Line City Of Angels The Breakfast Club Terminator 2 Judgement Day The Return of the King Save as ‘Favourite_Films.py’ Plenary Activity From here: http://www.computingacademy.org.uk/programming/introduction-programming-python l

More Related