A small project: a task list
Now we combine all the steps in one small project: you write a spec, get (or write) the code, read it, test it, fix it. The project: a task list. Each task is a dictionary: a name and a mark for whether it is done.
sonlar = []
sonlar.append(5)
sonlar.append(8)
print(len(sonlar))
print(sonlar[0])Output2
5list.append(x) adds an item to a list. A function can change a list that lives outside the function. Below is an example of adding values to a list.
The work starts from a spec: add, mark as done, get the ones left. After writing each function, test it with an example. You may write the project with the help of artificial intelligence, but read and test the result yourself.
Remember
- Project = spec + code + reading + testing + fixing.
list.append(x)adds an item.- Test every function with an example.
Exercise
Artificial intelligence instantly gave you the code for the whole project. Which is the right way?
Answer and explanation
- Read it in parts and test each part with an example. (correct answer)in small parts a bug is easier to find.
- Give it to users without testing.the bugs will reach the users.
- Skip reading it and trust the message “it worked”.running does not guarantee correctness.
Code exercises
- Write the task list:
qosh(nom)adds a task (a dictionary withnomandbajarildi),bajar(nom)marks it done,qolgan()returns a list of the names of tasks not done.
Hint: Each task is a dictionary{"nom": nom, "bajarildi": False}. Inqolgan()loop andappendto a new list the names of those whosebajarildiis false.
Do the exercise in the app.
Practical task
Add one new feature to the project (for example, deleting a task) and test it with 2 examples.
- I added the feature
- I tested it with 2 examples
Glossary
Interactive mode: search, progress and Python exercises.
