TM111_TMA_02-IT with complete solutions
Here is an example of how this program could be coded in Python: low_reading_list = [] def green_flag_clicked(): global low_reading_list low_reading_list = [] def space_bar_clicked(): name = input("Enter pupil's name: ") books_read = int(input("Enter the number of books the pupil has read, out of 20: ")) if books_read < 20: low_reading_d(name) green_flag_clicked() space_bar_clicked() print(low_reading_list) Step by step explanation: Detailed explanation: The first line of the code creates an empty list called low_reading_list which will be used to store the names of pupils who have read less than 20 books. The green_flag_clicked() function is defined. This function is called when the Green Flag is clicked in the program. The function uses the global keyword to indicate that it will be modifying the global low_reading_list variable, and then sets the value of low_reading_list to an empty list, effectively clearing it. The space_bar_clicked() function is defined. This function is called when the space bar is clicked in the program. Inside the function, two inputs are asked from the user: name: This is the name of the pupil, entered by the user as a string. books_read: This is the number of books that the pupil has read, entered by the user as an integer. Then there is an if statement which check if the number of books read is less than 20, If it is true then the name of the pupil is added to the low_reading_list using the append() method. Finally, the green_flag_clicked() and space_bar_clicked() functions are called, in that order. The green_flag_clicked() function is called first to clear the low_reading_list The space_bar_clicked() function is called next to prompt the user for the pupil's name and the number of books they've read, and then add the name to the low_reading_list if necessary. At last it prints the low_reading_list Please note that this is just one way of implementing this program and other ways are possible.
Written for
- Institution
- CLC
- Course
- CLC
Document information
- Uploaded on
- February 10, 2023
- Number of pages
- 6
- Written in
- 2022/2023
- Type
- Exam (elaborations)
- Contains
- Questions & answers
Subjects
-
tm111tma02 it with complete solutions