Some More Python Please ensure that youre logged on and ready to start

Embed Size (px)

DESCRIPTION

Please open up Python IDLE

Citation preview

Some More Python Please ensure that youre logged on and ready to start Hi! Welcome back to the IT Crowd Please open up Python IDLE 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!) 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!) What you write Exercise Warm up - Loops = Explanation Dont copy! print "Welcome to Python!" What you write A quick recap Welcome to Python What appears question= What\s your name? print(question) answer= input() (insert name here) print=( You\re called + answer + ?) question= What\s your name? print(question) answer= input() (insert name here) print=( You\re called + answer + ?) What you write An exercise from last time In review >>> print("You\'re called " + answer + " ?") You're called Nathaniel ? >>> print("You\'re called " + answer + " ?") You're called Nathaniel ? What you should see What should appear In review Lesson Todays Introduction Operators - Maths Maths in Python works much like Maths in real life. Youll need your Python maths for when youre making your games in a few lessons so, dont forget the basics and enjoy some of the more interesting tasks we have today Maths Try some of these: x = 2 y = 3 z = 5 x * y x + y x * y + z (x + y) * z Try some of these: x = 2 y = 3 z = 5 x * y x + y x * y + z (x + y) * z What you write Exercise Operators - Maths = Explanation Dont copy! How powers work: 2**8 256 How powers work: 2**8 256 What you write Exercise Operators - Maths = Explanation Dont copy! 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!) 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!) What you write Odd or Even? Operators - Maths = Explanation Dont copy! number = 7 guess = -1 count = 0 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!) number = 7 guess = -1 count = 0 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!) What you write Guess the number Operators - Maths = Explanation Dont copy! Its long but interesting. Have a go guessing with the person next to you! 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 dont like your name') 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 dont like your name') What you write Nice name or not? Operators - Maths = Explanation Dont copy! 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!) 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!) What you write Adding and printing Operators - Maths = Explanation Dont copy! Thanks for coming, to keep updated: Or visitGIMP After the holidays