Preview

03 - Tutorial #1+Past Paper Qs - if, string manip

 1. The following presentation presents a programming problem and takes you through the steps to solve it. Select 'Yes', when complete. (1 mark)

  No

  Yes

 2. On being presented with a programming problem, it is important to break the problem down. What is this called? (1 mark)

 3. Any given program can be divided into three main parts - what are they? (3 marks)

 4. Name all the variables in this program. (3 marks)
firstname=input("Enter your first name:")
lastname=input("Enter your last name:")
gender=input("Enter your gender:")
 if gender=="male":
username= lastname[-4:]+firstname[0:2]
else:
username=firstname[0:3]+lastname[0:2]
 print(username)

 5. What data type is likely to have been used (Python does this by default) for the firstname and lastname variables? (1 mark)

 6. The programmer wishes to add another variable to the program - Over16. It will be either True or False depending on whether the user is above the age of 16. What data type is this? (1 mark)

 7. A final variable called 'pocketmoney' e.g. ?3.50 is also to be added to the program. What data type would be suitable for this variable? (1 mark)

 8. Name all the constants in this program (1 mark)
firstname=input("Enter your first name:")
lastname=input("Enter your last name:")
gender=input("Enter your gender:")
 if gender=="male":
username= lastname[-4:]+firstname[0:2]
else:
username=firstname[0:3]+lastname[0:2]
 print(username)

 9. Name the programming constructs used in this program. (Sequence,Selection,Iteration) (2 marks)
firstname=input("Enter your first name:")
lastname=input("Enter your last name:")
gender=input("Enter your gender:")
 if gender=="male":
username= lastname[-4:]+firstname[0:2]
else:
username=firstname[0:3]+lastname[0:2]
 print(username)

 10. The following program seeks to isolate the first four characters from any given entered string. Correct line 2 such that it produces the correct output. E.g. input: "ABCDEFG" would output "ABCD" (2 marks)
word=input("Enter a string of letters:")
newword= word[2:4]
print(output)