Presentation is loading. Please wait.

Presentation is loading. Please wait.

You should have C:\100 folder A shortcut to Python IDLE on desktop.

Similar presentations


Presentation on theme: "You should have C:\100 folder A shortcut to Python IDLE on desktop."— Presentation transcript:

1 You should have C:\100 folder A shortcut to Python IDLE on desktop

2 Recap Python has value types: int, float, str, boolean
Variables vs. functions Both follow the naming convention Names are case-sensitive Lower-case first word, first letter capitalized in subsequent words A variable is assigned a value and hold it A function returns a value with a given argument

3 Input/Oupt Functions print(): print out the text in the argument
input(): get Python ready to accept a response (nothing in argument) print(‘What is your age?’) myAge = input() What value will the variable myAge have ?

4 Past Lab 0907 Ask what the name is Ask what the major is
Ask when you started the school Print “My name is …. studying ... from ....” >>> print(“What is your name?”) >>> myName = input() Kim >>> print (“What is your major?”) >>> myMajor = input() CS >>> print (“When did you start the school?” >>> myStartYr = input() 2000 >>> print(‘My name is ‘ + myName + ‘ studying ‘ + myMajor + ‘ from ‘ + myStartYr)

5 Programming in a File Python IDLE shell lets you write a program only once Need to save a program and reuse it later on Click on ‘File’ menu in IDLE, and select ‘New File’ A new file window opens up Enter the following instructions in the new window myName = input('Enter your name\n’) myMajor = input('Enter your major\n') myStartYr = input('Enter your start year\n’) print('My name is ' + myName + ' studying ' + myMajor + ' from ' +myStartYr)

6 How to run the program ? Click on menu ‘File’ and select ‘Save as’
Save the file under C:\100 with the name, test You should have a file C:\100\test.py Click on menu ‘Run’ and select ‘Run Module’ Back in IDLE window, the first query should show up Provide answers and see the final print() function prints out the sentence. myName = input('Enter your name\n’) myMajor = input('Enter your major\n') myStartYr = input('Enter your start year\n’) print('My name is ' + myName + ' studying ' + myMajor + ' from ' +myStartYr)

7 Review In the program, test.py, what are variables ?
myName = input('Enter your name\n’) myMajor = input('Enter your major\n') myStartYr = input('Enter your start year\n’) print('My name is ' + myName + ' studying ' + myMajor + ' from ' +myStartYr) In the program, test.py, what are variables ? In the program, test.py, what are functions?

8 When to use IDLE and File
Any programs to be reused or edited should be in files IDLE to test out a few instructions In IDLE, enter the following >>> myYr = input(‘What is your age? \n’) What is your birth year? 1990 >>> type(myYr)

9 HW1 – due on Wed class (9/14) Do problems 1, 2, 6, 7, 10
from Practice Questions in Chap. 1.

10 Lab 0909 Create a new file and write a program to ask your current age and print out your age in 5 year ? Namely, complete the print() function below: (Caution: the date type of the variable ‘myYr’ is a string.) myYr = input(‘What is your age? \n’) print(‘My age in the next 5 years will be ‘ Run your program, and the screen shot to


Download ppt "You should have C:\100 folder A shortcut to Python IDLE on desktop."

Similar presentations


Ads by Google