![]() Let's break down the solution and comment on some complex or interesting things.Ġ:20 - As starting point we'll use an image with Golang logo. Your best friend is having an 11th birthday party, and as a gift you’ve decided to code them a scarf! Use calculations wherever possible to make your own scarf pattern.Disclaimer: never use this code in production. Save Your Project Challenge: Code a scarf You could even use calculations to make interesting patterns, like this wave: print ( "/\ "* 10) print ( " \/"* 10) screenshot Or you could save time and draw it the easy way, like this: print ( "#" * 30) print ( "#" * 30) print ( "#" * 30)īoth give you exactly the same rectangle printed to the screen: screenshot You could either draw it the hard way, like this: print ( "#") print ( "#") print ( "#") Now that you know how to do calculations on text, now what? Why is it useful? Well, let’s say you wanted to draw an ASCII art rectangle that is 30 characters long and 3 characters high. print ( "ha "* 4) print ( "ba" + "na"* 2) print ( "He" + "l"* 2 + "o" + "!"* 10)Ĭan you make up any words of your own? Save Your Project Step 4: ASCII patterns Activity Checklist What does the following program print to the screen? See if you can guess correctly before running the program. Save Your Project Challenge: Words and numbers How about addition? What answer do you think "hello " + "world" would give? Try it out, by running the following program: print ( "hello " + "world") screenshotĭoes it give you the answer you expected? It looks like that calculation doesn’t make sense in Python! Oops, you’ve broken it! Instead of an answer, we get an error message. ![]() If "hello " multiplied by 5 is "hello hello hello hello hello ", then what is "hello" - 7? Does this calculation even make sense? screenshot Run this program and you’ll see that the output is a little easier to read than before. You can make the printed text above easier to read, by putting a space after the word "hello" in your program: print ( "hello " * 5) Run the program above, and you should see the answer: screenshot The star * in the program above is a multiply sign. Python can also do calculations using text! What do you get if you multiply "hello" by 5? Let’s ask Python, by running this program: print ( "hello" * 5) You can create images of your hobbies, friends, family… anything you want! Here’s an example: screenshot Save Your Project Step 3: Calculating text Activity Checklist Write a Python program to tell others about yourself, by using text and ASCII art. Save Your Project Challenge: About yourself If you run this program, you’ll see it prints the same dog as before. If you prefer, you can use 3 single quotes ( ''') instead of speech marks, which allows you to print multiple lines of text with 1 print statement. To make this masterpiece, you can type the following into the IDLE editor and run the program: print ( "A picture of a dog.") print ( " 0_ ") print ( " |||| ") Here’s an example - it’s meant to be a dog! screenshot Let’s print something much more fun than text… ASCII art! ASCII art is creating pictures out of text. Save Your Project Challenge: What’s on your mind?Ĭhange the program above to print something more interesting to the screen! screenshot Save Your Project Step 2: About yourself Activity Checklist If you’ve made a mistake, for example missing out a speech mark ( "), then you’ll get an error message instead, telling you what went wrong! Try it! screenshotĬongratulations, you are now officially a Python programmer! Give yourself a pat on the back (or if you’re feeling lazy, get someone else to do it for you). If everything has worked properly, you should see your text printed to the screen. This is the place that your program will run. ![]() You should see another window appear, which is the Python shell. Run the file by clicking Run → Run Module. Without it, your program won’t be colour coded, which can be really helpful. py bit at the end, which tells the computer that it’s a Python file. Save the file, by clicking File → Save, and name the file hello.py or something similar. Here’s an image showing what you need to do: screenshot Notice that the text you want to print is surrounded by speech marks ( "). ![]() This program will print some text to the screen. ![]() On Linux, open up a Terminal, and type idle and press enter.Ĭlick File → New Window, and type the following into the window that appears: print ( "Hello, how are you?").On Mac, open up Terminal.app and type idle and press enter.On Windows, find IDLE in the start menu.Let’s start by writing a very simple program, just so that you know how to get a Python program running.Python allows you to turn a series of instructions into useful programs and fun games! In this project you’ll learn how to run a Python program, and how to print text to the screen. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |