More advanced stuff

Download Report

Transcript More advanced stuff

Some More Python
Please ensure that you’re logged on and ready to start
Hi!
Welcome back to the
IT Crowd
Please open up
Python IDLE
= Explanation
Don’t copy!
Warm up - Loops
Exercise
What you write
Loops do just what they say in the title, repeat
programs over and over and never end! Try:
while 1 == 1:
print(“Over and over, looping out of control!”)
A quick recap
What you write
print "Welcome to Python!"
What appears
Welcome to Python
In review
An exercise from last time
What you write
question= “What\’s your name?”
print(question)
answer= input()
(insert name here)
print=(“ You\’re called ” + answer + “ ?”)
In review
What should appear
What you should see
>>> print("You\'re called " + answer + " ?")
You're called Nathaniel ?
Todays
Lesson
Operators - Maths
Introduction
Maths in Python works much like Maths in real life. You’ll need your Python maths for when
you’re making your games in a few lessons so, don’t forget the basics and enjoy some of
the more interesting tasks we have today
Maths
= Explanation
Don’t copy!
Operators - Maths
Exercise
What you write
Try some of these:
x=2
y=3
z=5
x*y
x+y
x*y+z
(x + y) * z
= Explanation
Don’t copy!
Operators - Maths
Exercise
What you write
How powers work:
2**8
256
= Explanation
Don’t copy!
Operators - Maths
Odd or Even?
What you write
Odd or even, this script will react to print what
the number is:
number = float(input(“Feed me a number: "))
if number % 2 == 0:
print(int(number), "is even.")
elif number % 2 == 1:
print(int(number), "is odd.")
else:
print(number, "is very strange.”)
(Keep repeating and try different numbers!)
= Explanation
Don’t copy!
Operators - Maths
Guess the number
What you write
number = 7
guess = -1
count = 0
It’s long but interesting.
Have a go guessing with the
person next to you!
print("Guess the number!")
while guess != number:
guess = int(input("Is it... "))
count = count + 1
if guess == number:
print("Yay! You guessed right!")
elif guess < number:
print(“Keep guessing, bit bigger…")
elif guess > number:
print(“Thats way too big, try going lower”)
if count > 3:
print(“Took you a while but you got there.")
else:
print(“Hats off to you, clever clogs!”)
= Explanation
Don’t copy!
Operators - Maths
Nice name or not?
What you write
name = input('Your name: ')
if name == 'Ada':
print('That is a nice name.')
elif name == ‘Your friend':
print(‘something bad about their name')
elif name == ‘Another friend:
print(‘Be imaginative')
else:
print('I don’t like your name')
= Explanation
Don’t copy!
Operators - Maths
Adding and printing
What you write
This will calculate your number, if its bigger
than or less than 100 it will show messages.
number1 = float(input('1st number: '))
number2 = float(input('2nd number: '))
if number1 + number2 > 100:
print('That is a big number.’)
else:
print(‘That is a small number!’)
(Keep repeating and try different numbers!)
GIMP
After the holidays
Thanks for coming, to keep updated:
: @BittTeam
Or visit http://itcrowd.gweb.io