Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please refer to our video player troubleshooting guide for assistance.

Challenge: Space Race

00:00 Welcome to the Challenge. It’s a space race, and you need to start fresh. So don’t work with the code you already created, but create a new file to tackle this challenge.

00:11 Since it’s a challenge, it’s a bit bigger and it’s separated into different slides. So bear with me.

00:18 Create a dictionary named Captains by using this list of pupils: Enterprise, Picard, Voyager. Janeway, Defiant, Sisko. It’s a list with three items.

00:30 The items are pupils, and the first pupil is Enterprise, Picard. The second one, Voyager, Janeway, and the third one, Defiant, and Sisko. And all of the contents of the pupils are strings.

00:44 After you create a dictionary, add another spaceship named Old Besi with Captain Lila to captains. Next, store a list of the spaceship names in a variable spaceships,

01:00 and then the race starts. Randomly pick three spaceships from the spaceships list and store them in a new list named positions.

01:10 For this, you can use the random module and here is a little code example on how to use it if you haven’t used the random module.

01:16 First, you need to import random. Then there is probably some code that you will write on your own. Then you can define a positions list with random.sample, and then in parentheses as one argument, spaceships.

01:31 And then as the second argument, the length of the spaceships list, which is len(spaceships).

01:38 Once we tackle these code snippets in the live coding session, I will explain this code more thoroughly. Of course, after that, you need to create a dictionary named winners with the keys one, two, and three.

01:53 And the default values should be the string unknown for each key.

01:59 And finally, loop over the captains dictionary and congratulate the captain of the ship that made it to the first place and motivate the captain who didn’t make it to the top three, for example, “Better luck next time, Picard. Congratulations, Sisko.” So in this case, Picard didn’t make it to the top three and Sisko made it to the first position.

02:22 Alright, that’s quite a bit, but hey, it’s a challenge. You can stop this video course, take all the time you need. You can download the slides and the corresponding materials that you can download below this video course.

02:34 And once you are finished solving the space race, you can continue with the video course where you can see how I solve this challenge. Good luck.

Become a Member to join the conversation.