AI Ustoz UZ: learn artificial intelligence in Uzbek

Asking artificial intelligence for code and reading it

Intermediate level · lesson 2 · about 12 min

When you ask for code, state: the language, the function name and purpose, input and output, 2–3 examples and constraints (for example, no outside libraries). Then you get short, understandable code that you can read.

def toq_sonlar(royxat):
    natija = []
    for son in royxat:
        if son % 2 == 1:
            natija.append(son)
    return natija

print(toq_sonlar([1, 2, 3, 4, 5]))
Output[1, 3, 5]

Before running the code you receive, read it line by line. In the example below % gives the remainder: son % 2 == 1 means an odd number. append adds an item to the end of a list. If you cannot explain a line in your own words, ask the tool about that line.

The tool’s explanation can also be wrong, so check your understanding with a small example yourself. Being able to read and change code is the key skill of vibe coding.

Remember

  • In the request give language, task, input/output, examples and constraints.
  • Read code line by line before running it.
  • Check the tool’s explanation on a small example too.

Exercise

Artificial intelligence gave you code. What should you do first?

Answer and explanation
  1. Use it right away and add it to the project.code you do not understand and have not tested is risky.
  2. Read it line by line, understand what it does, then try it on examples. (correct answer)reading and testing give grounds to trust the code.
  3. Check only whether it is written nicely.nice-looking code can be wrong too.

Code exercises

  1. Change the jami_narx function written by artificial intelligence: when 10 or more items are bought, a 10 percent discount applies (the total is multiplied by 0.9).
    Hint: First jami = narx * soni, then if soni >= 10: multiply jami by 0.9, then return jami.

Do the exercise in the app.

Practical task

Write a code request for a small function (language, task, input/output, 2 examples, a constraint). Do not enter real personal data.

  • I wrote the request
  • It has an example and a constraint

Glossary

Interactive mode: search, progress and Python exercises.