Download presentation
Presentation is loading. Please wait.
Published byAnnabel Ashlie Eaton Modified over 6 years ago
1
Week 2 Computer Programming Learning Objective:
Gray , Calibri 24 Dark Red RGB , Calibri 54 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
>>> (has chevrons)
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
What is the purpose of my_name in this program?
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_name in this program?
4
Variable Data Variable_Name Data
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. Variable_Name Data Assignment In Python, it looks like this Name = ‘Tom’
5
userName =input("Please type your name in")
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 userName Save & Run the program (F5) to test it.
6
BUT! Python allows us to print a bunch of letters
Edit your program and add the bottom line of code… 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
How does this program work?
Add another question by copying and pasting lines 2 and 3 CHANGE the variable names Save it and then Run it (F5) How does this program work?
8
Edit your program further by adding a 3rd question
Save it and then Run it (F5) print ("I am a computer...") userName = input("What is your name") print ("Hello " + name + ", nice to meet you") favouriteFood = input ("What's your favourite food?") print ("Wow, i love " + favouriteFood + ", too!") 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? 0:41 0:40 0:42 0:45 0:39 0:44 0:43 0:37 0:34 0:33 0:35 0:36 0:46 0:38 0:49 0:56 0:55 0:57 0:58 1:00 0:59 0:54 0:53 0:32 0:48 0:50 0:51 0:52 0:47 0:30 0:11 0:10 0:12 0:13 0:15 0:14 0:09 0:08 0:03 End 0:04 0:05 0:07 0:06 0:16 0:17 0:26 0:25 0:27 0:28 1:01 0:29 0:24 0:23 0:19 0:18 0:20 0:21 0:22 0:31 1:02 1:41 1:40 1:42 1:43 1:45 1:44 1:39 1:38 1:34 1:03 1:35 1:36 1:37 1:46 1:47 1:56 1:55 1:57 1:58 2:00 1:59 1:54 1:53 1:49 1:48 1:50 1:51 1:52 1:32 1:33 1:12 1:11 1:13 1:14 1:31 1:15 1:10 1:09 1:05 1:04 1:06 1:07 1:08 1:17 1:16 1:27 1:26 1:28 1:29 1:30 1:18 1:25 1:24 1:19 1:21 1:20 1:22 1:23 0:01 0:02 Print(‘Hello World’)
9
Save as ‘Favourite_Films.py’
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: l
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.