Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lesson 4 - Challenges.

Similar presentations


Presentation on theme: "Lesson 4 - Challenges."— Presentation transcript:

1 Lesson 4 - Challenges

2 Python Where do you find Python? How do you start a new program?
Start / Computer / ICT (I:) / Python / IDLE In Python go to: File / New File How do you run a program? What is a string? Press the F5 key (on the top row) A sentence. And it is usually in green surrounded by quote marks and brackets.

3 Last Lesson for x in range (1, 5): print (x * 6)
You learnt about For loops What do the following two programs do? for x in range (1, 5): print (x * 6) for x in range (1, 51): print (x * 9)

4 Last Lesson subject = ”computing” guess = ”” while guess != subject:
You learnt about While loops What does the following program do? subject = ”computing” guess = ”” while guess != subject: guess = input("Please guess my favourite subject: ")) print("You guessed the correct subject!")

5 Sequence Challenge 1 name = input(“???“) print(”??? ” + name)
Create a program to ask the user their name and output it once they press Enter on the keyboard. Create one variable called name. Use one print statement. Make use of the + sign in the final line. HELP name = input(“???“) print(”??? ” + name) MORE HELP Save it as seqchal1.

6 Sequence Challenge 2 Create three variables.
Create a program to ask the user their name, age and favourite subject. This should be output using one print statement. Create three variables. Remember int when working with numbers. Use one print statement on the final line. Make use of multiple + signs in the final line. HELP name = input(“???“) age = int(input(“???“)) school = input(“???“) print(”??? ” + name + “ ???” +…) MORE HELP Save it as seqchal2.

7 The rest of the program must be indented.
Repetition Challenge 1 Add the following lines at the top of your previous program. This will make the program loop indefinitely. flag = True while flag == True: The rest of the program must be indented. flag = True While flag == True: name = input(“???“) age = int(input(“???“)) school = input(“???“) print(”??? ” + name + “ ???” +…) HELP

8 Make use of multiple + signs in the final line.
Selection Challenge 1 Create a program to ask the user their age and if it is 18 or more it should output, you are an adult, otherwise it should output you are a child. It should loop. Create one variable. Use an If Else command. Make use of multiple + signs in the final line. Use a While loop. HELP age = int(input(“???“)) if ??? >= ???: print(”???”) else: MORE HELP Save it as selchal1.

9 Selection Challenge 2 Create one variable. Use an If Else command.
Create a program to ask the user their age and if it is between 4 and 16 it should output “You are in school”, otherwise output “You are not of school age”. Create one variable. Use an If Else command. Use more than one operator < and >. Make use of the AND keyword after the IF statement. HELP age = int(input(“???“)) if ??? >= ??? and ??? <= ???: print(”???”) else: MORE HELP Save it as selchal2.

10 Use a While loop to make this program repeat.
Selection Challenge 3 Create a program to ask the user the direction they would like to go in. If they go left it displays “You have gone into a cave”, if they say right it displays “You have fallen off the cliff!”. Otherwise it should say, “You are stuck on an endless path.” direction = input(“???”) if direction.lower() == “left”: print(“???”) elif direction.lower() == “???”: print(“??? ”) else: print(“You are stuck..”) HELP Use a While loop to make this program repeat. Save it as selchal3.

11 Create a program to output the 7 times table up to 10.
Repetition Challenge 2 Create a program to output the 7 times table up to 10. Set x to 1. Use a For loop. Remember the first number in a loop is where it starts, and it finishes before the final number. HELP for x in range (1,???): print (x * ???) MORE HELP Save it as repchal2.

12 Repetition Challenge 3 Use a For loop.
Create a program to ask the user to print out the cubed numbers from 13 to 103. Use a For loop. Remember the first number in a loop is where it starts, and it finishes before the final number. HELP for x in range (1,???): print (x * ??? * ???) MORE HELP Save it as repchal3.


Download ppt "Lesson 4 - Challenges."

Similar presentations


Ads by Google