1. Python is a high level programming language that is growing rapidly in popularity and use.
2. Python was created and developed by ...
3. Python has many applications and uses including:
4. One of the simplest things you can do in Python is print "Hello World" to the screen. The following code has been written in python and produces the output: "Hello World"
5. What is the OUTPUT from the following program?
6. A variable can be thought of as ...
7. What are the variables in the code below?
8. Consider the following list of elements and that you are looking for number 7. A linear search would be quicker than a binary search in this example.
9. In a LINEAR SEARCH, if you were looking for the number 18 in the following list, you would:
10. The Binary search algorithm is often referred to as a 'divide and conquer' algorithm because ...
11. The disadvantage of a Binary Search algorithm (as compared to a linear search) is that the list being searched must be SORTED (i.e. in order). A Binary search would not work if the list was unsorted.
12. Which searching algorithm is more efficient on a sorted list? Linear Search or Binary Search?
13. Suppose you have the following sorted list (see list below) and are using the binary search algorithm. What are the first two numbers you would 'find' if you were looking for the number 8?
14. Follow the logic in the program below. What will the output be on running this program?
15. The following program will fail to run. What do you need to add on line 4?
16. The following code uses Boolean variables that can be either TRUE or FALSE. What is the output of the following program?
17. The output of this program will be 5.
18. Can you explain what is happening on line 4?
19. What is missing from line 8?
def main():
x=10
y=20
z=30
avg=average(x,y,z)
print(avg)
def average():
return (x+y+z)/3
main()
The parameter 'avg' is missing. It should be: def average(avg):
The parameters x,y,z! It should be: def average(x,y,z):
Nothing is missing!
The variables a,b,c! It should be: def average(a,b,c):
20. An architectural company would like a program that calculates the area of a given piece of rectangular land, given its width and height. What would happen on entering 100.01 and 200.23 into the program below?
21. The code below seeks to take the temperature in celsius and convert it into fahrenheit. Can you spot the error in the code below?
22. A user wishing to convert pounds to dollars inputs '10' into the program below, and the output is: 1010. Can you explain why?
23. In the code below the two variables with 'string' data types are 'a' and 'b'. Strings are typically always put in speech marks. e.g. name="Joe"
24. A education company in the UK is creating a program in which they need to store the names of each student. What is the most appropriate data type for 'first name'?
25. The following program seeks to find the average of three test scores. How would you complete the code on line 5?
27. Another example of Validation is ensuring that a 'password' entered by the user is at least 6 characters long and contains both numbers and special characters to make it secure.
28. It is not at all important to add validation in programs, as most programs manage just fine without it.
29. One method of validation is shown below using the 'try' and 'except' coding method. What will happen if you try to enter: "3fx" into the program below?
30. Another simple method of coding validation is to use a LIST to store the accepted inputs. If we wanted lowercase 's' as well as uppercase 'S' to be accepted what would you do?
31. A good programmer will not only build in validation(to prevent invalid and silly input) but may also add validation messages which ...
32. The if elif else statement is used in Python for ...
33. In the following code that uses selection (if statements) what is the output? Note, that the input is num=7.
34. The program below asks the user for their budget and according to the input, presents them with a list of expensive or cheap laptops. If the user enters 4000, what would the output be?
35. The code below checks an input email for an @. Why will the code fail to run?
36. In the below code, can you spot and point out the mistake on lines 2 and 3?
37. SPOT THE ERROR QUESTION: Spot the error (which line?) and explain what it is.
38. SPOT THE ERROR: Sometimes, the error is not on the line that your IDLE tells you it is on, but on the line before. Error checking would tell you there is an error on line 3. Is it right?
40. The following program will NOT run because the call to the instagram subroutine (at the bottom on line 6) is not to the extreme left (which will cause an error)
41. What is wrong with the following code snippet?
42. In programming, operators are symbols that tell the computer to perform specific mathematical, relational or logical operations on data. What operators can you spot in the code below?
43. Trace the logic in the code below to predict the output of score on line 4.
44. The formula to calculate the area of a circle is: Area=PI times radius squared. PI=3.14. What would you need to add to line 8 to get the program working correctly.
45. Analyse the code below to see what it does. If you entered two numbers: 2, and 66, it should produce the result: ('Largest of entered two numbers is', 66). What needs to go on line 11?