NUSH CS1131 Revision Paper 2 Notes
Uploaded by lxysgp · 21 November 2025
Preview
CS1131 Notes Computational Thinking I Revision Paper 2 Worked Solutions Links of All LQ Notes: LQ Notes Links Document Topics Question 1 Question 2 Question 3 Question 4 Question 5 Disclaimer This is a set of notes going through Revision 2: More practices from NUS High Coursemology, since it seems many of you guys have a few concerns / are struggling a bit with it. Again, since this contains information from NUS High Coursemology, please do not share this set of notes outside of your NUS High Y1 Classmates. Thank you :D Good luck! ~LQ (25 Sep)
Solution First, we notice that this is just the sum of the cubes from 1 to 60 (i.e. 1 3 + 2 3 + … + 60 3 ). Let’s first define the variable resultA , which should start at 0. We use resultA = 0 . 1 2 resultA = 0 Now, since the sum starts with 1 3 and ends with 60 3 , we should loop over the values 1 to 60. In this case, we use range(1, 61) because range ends at one number before what’s specified. 1 2 3 4 resultA = 0 for n in range(1, 61): Now, since every term should be cubed, before being added to the resultA variable, we use the operation n ** 3 , then add that to resultA. 1 2 3 4 5 resultA = 0 for n in range(1, 61): resultA = resultA + n ** 3 Finally, we print out resultA. 1 resultA = 0
2 3 4 5 6 7 for n in range(1, 61): resultA = resultA + n ** 3 print(resultA) And that’s our solution.
Solution Let’s first define the variable resultB , which should start at 0. We use resultB = 0 . 1 2 resultB = 0 We then take a user input for n, and store it as a variable. Do recall that the input() function gives a string (i.e. text), so we should convert it into an integer before we can do much with it. 1 2 3 resultB = 0 n = int(input("Enter n: ")) Now, we see each term has alternating sign (i.e. plus, then minus, then plus, and so on…), we should define a variable sign to keep track of that. Since the first term is positive, we let sign be 1 . 1 2 3 4 resultB = 0 n = int(input("Enter n: ")) sign = 1 Since the first term is and the last term is , there are n terms in total, so we use 1 2 𝑛 𝑛 + 1 range(1, n+1) .
1 2 3 4 5 6 resultB = 0 n = int(input("Enter n: ")) sign = 1 for i in range(1, n + 1): Now, we recognise that the i-th term is just , multiplied by the sign variable. Then, we 𝑖 𝑖 + 1 add this to resultB . 1 2 3 4 5 6 7 resultB = 0 n = int(input("Enter n: ")) sign = 1 for i in range(1, n + 1): resultB = resultB + i *
Content continues in the PDF.
Related notes
- NUSH CS1131 NotesNotes/Practices · 2025
- RI Y3 CEP Using DB Browser for SQLite 2021Notes/Practices · 2021
- RI Y3 CEP Using DB Browser for SQLite 2021Notes/Practices · 2021

