Stephen Gruppetta

0 Followers
43 Following
73 Posts
• Rethinking how to teach #coding • Writes about #Python on ThePythonCodingBook.com/blog and at RealPython • Former Physicist • #Programming #fedi22
The Python Coding Book – The Bloghttps://thepythoncodingbook.com/blog
The Python Coding Bookhttps://thepythoncodingbook.com
Codetodayhttps://codetoday.co.uk
Curated Collection of Python Threadshttps://typefully.com/s_gruppetta_ct
A Python Lunar Landing game using the turtle module

A Python Lunar Landing program that uses the turtle module. The article guides you through the program in a step-by-step approach

The Python Coding Book

One of the most fun modules in #Python is the `turtle` module, but…

I can hear you think "That's only for simple, boring drawings, and nothing else, right?"

Think again – see video

If you want to have a go at writing this game, there's a details step-by-step tutorial here, one of the most popular on The Python Coding Book Blog:

https://thepythoncodingbook.com/2022/04/24/python-lunar-landing-game-using-turtle-tutorial/

#animations #games #programming

A Python Lunar Landing game using the turtle module

A Python Lunar Landing program that uses the turtle module. The article guides you through the program in a step-by-step approach

The Python Coding Book

I sometimes struggle to recall which of the / or * symbols does what

To remember which is which, you can note that the asterisk * is the same as used when creating *args

In fact, you could replace * with *args and the function will work in a similar manner in this case

/16

*args is "mopping up" all remaining positional arguments before the keyword arguments – keyword arguments always come after positional ones in a function call

In this example, there are no additional positional arguments to "mop up", so `args` is an empty tuple

/17

Note that if using *args, all arguments before the *args need to be positional so the / is no longer needed in this case

/18

Just using * instead of *args takes care of this scenario and therefore forces the remaining parameters to be used with keyword-only arguments

/19

We'll now move on to the final part of this series on Python functions and talk about making functions neater, more readable, and possible minimise bugs by use type annotations and docstrings

/20

In the function definition, `greeting` is before the forward slash /

Therefore, the argument assigned to `greeting` must be a positional-only argument

/13

Parameters before the forward slash / : must use positional-only arguments

Parameters after the asterisk * : must use keyword-only arguments

Parameter in between / and * : can be either positional arguments or keyword arguments

/15

Therefore the argument which matches `repeat` is a "normal" one. It can be passed either as a positional argument or as a keyword argument

The user who's calling the function can choose

/11