ENGG1003_Lab08_PythonBasics (1)
ENGG1003_Lab08_PythonBasics (1)
Extras
Variables and Expressions
temperature = 24.6
humidity = 0.75 Key-in OR copy-and-
print(temperature > 24) paste
print(humidity > 0.85) one line at a time!
Practice on print(temperature >= 24 or humidity < 0.7)
print(22 < temperature < 28)
IDLE (Python)
approx_dew_point = temperature - (100 - humidity * 100) /
print('Dew point =', approx_dew_point)
Try different test
User Input cases.
What do you see?
File New File, enter the following code:
Name? Mike
Year? 2
name = input("Name? ")
GPA? 2.99
year = int( input("Year? ") )
gpa = float( input("GPA? ") )
print("Year", year, "friend", name, "!") Name? Ann
if gpa >= 3.0: Year? 4
print("Marvel!")
GPA? 3.78
elif gpa > 2.2:
print("Keep up!") Name? Pete
else: Year? 1
print("Work hard!") GPA? 2.1
b a+b>c
print the message ”Formed a triangle!" or a
a+c>b
"Not a triangle!" b+c>a
Run, test and verify your work thoroughly c
and carefully (think of some more test
cases):
a? 2 a? 2 a? 3
b? 3 b? 5 b? 6
c? 4 c? 10 c? -5
Formed a triangle! Not a triangle! Not a triangle!
Category Wind Speed (mph)
pet.speed(0)
if x % 2 == 0:
pet.pencolor('black')
else:
pet.pencolor('blue')
pet.forward(x)
pet.left(59) % is the remainder operator.
pet.pencolor('red')
x % 2 == 0 is an even-odd integer test.
pet.forward(270)
pet.exitonclick()