Python Basics
Variables, numbers, text, functions, decisions, lists and loops: the Python every robot lesson builds on. Each step is a short program that's checked the moment you run it, with examples taken from the robot arm you'll program next.
Start the lesson0/7 steps done
What you'll learn
- Store values in variables and print them
- Do arithmetic and convert degrees to radians
- Build readable messages with f-strings
- Write functions that take parameters and return results
- Make decisions with if, elif and else
- Read, add to and slice lists
- Loop over lists to add up values and find the closest item
Before you start
No programming experience needed: this lesson starts from your very first line of Python. Everything runs in your browser. The first visit downloads Python and the simulator, about 20 MB, and later visits load from your browser's cache.
Steps
- 1Hello, robotRun your first program, print to the console and store values in variables.printStrings and numbersVariablesCommentsOpen
- 2Numbers and mathsUse Python as a calculator, import the math module and convert degrees to radians.Arithmeticints and floatsThe math moduleRadiansOpen
- 3Working with textJoin strings, call string methods and build readable messages with f-strings.StringsMethodsf-stringsNumber formattingOpen
- 4FunctionsPackage a calculation as a function with parameters, and return its result.defParametersreturnIndentationOpen
- 5Making decisionsCompare values, and choose what to do with if, elif and else.BooleansComparisonsif / elif / elseand / orOpen
- 6ListsKeep many values in one list, read items by index and add new ones.ListsIndexingappendinSlicingOpen
- 7LoopsRepeat work for every item in a list: add up totals and find the closest ball.for loopsrangeRunning totalsBest so farOpen