number: result="Low" else: result="High" return result # Collect the user's guess as an integer guess = int(input("Can you guess it? ")) # Use our function higher_or_lower = is_same(computer_number, guess) # Run the game until the user is correct while higher_or_lower != "Win": if higher_or_lower == "Low": guess = int(input("Sorry, you are too low. Try again. ")) else: guess = int(input("Sorry, you are too high. Try again. ")) higher_or_lower = is_same(computer_number, guess) # End the game input("Correct!\nWell Done\n\n\nPress ENTER to exit.")"> number: result="Low" else: result="High" return result # Collect the user's guess as an integer guess = int(input("Can you guess it? ")) # Use our function higher_or_lower = is_same(computer_number, guess) # Run the game until the user is correct while higher_or_lower != "Win": if higher_or_lower == "Low": guess = int(input("Sorry, you are too low. Try again. ")) else: guess = int(input("Sorry, you are too high. Try again. ")) higher_or_lower = is_same(computer_number, guess) # End the game input("Correct!\nWell Done\n\n\nPress ENTER to exit.")">

Presentation is loading. Please wait.

Presentation is loading. Please wait.

Coding Time This is a starter activity and should take about 10 minutes [ slide 1 ] 1.Log in to your computer 2.Open IDLE 3.Start a script session (Select.

Similar presentations


Presentation on theme: "Coding Time This is a starter activity and should take about 10 minutes [ slide 1 ] 1.Log in to your computer 2.Open IDLE 3.Start a script session (Select."— Presentation transcript:

1 Coding Time This is a starter activity and should take about 10 minutes [ slide 1 ] 1.Log in to your computer 2.Open IDLE 3.Start a script session (Select New Window from the File menu.) 4.Copy the code from Code Box 4.4 on page 51 and 52 into your file. 5.Save your file as myNumber.py Top Tip: Think about what the code is doing as you type. There are only two bits of code you will not recognise: return and int() If you have finished: Check your code carefully and then run it: ( Run Module from the Run menu )

2 Lesson Aims [ slide 2 ] Vocabulary data-types casting In this lesson you are going to: 1.Learn more about writing your own functions 2.Learn about the return keyword 3.Learn about casting

3 Code analysis [ slide 3 ] # The is_same() function def is_same(target, number): if target == number: result="Win" elif target > number: result="Low" else: result="High" return result # Collect the user's guess as an integer guess = int(input("Can you guess it? ")) # Use our function higher_or_lower = is_same(computer_number, guess) # Run the game until the user is correct while higher_or_lower != "Win": if higher_or_lower == "Low": guess = int(input("Sorry, you are too low. Try again. ")) else: guess = int(input("Sorry, you are too high. Try again. ")) higher_or_lower = is_same(computer_number, guess) # End the game input("Correct!\nWell Done\n\n\nPress ENTER to exit.")

4 Taking it further [ slide 4 ] Work through the Ideas from page 54

5 Optional Homework Try any of the Ideas from page 54 [ slide 5 ]

6 Lesson Summary [ slide 6 ] In this lesson you have: 1.Learnt more about writing your own functions 2.Learnt about the return keyword 3.Learnt about casting Vocabulary 1. What is the keyword we use if we want a function to produce a value? 3. What word describes the process in question 2? 2. What function do we use if we want to change a number which is a string data-type into an integer? int() casting return


Download ppt "Coding Time This is a starter activity and should take about 10 minutes [ slide 1 ] 1.Log in to your computer 2.Open IDLE 3.Start a script session (Select."

Similar presentations


Ads by Google