Statements
Let's open our Python IDLE and start with statements. One of the functions we will be using the most is the print() function. You can check for more Python-built-in functions and how they operate at https://docs.python.org/3/library/functions.html.
print("Hello World")
Hello world
After typing our statement in the file as shown below, we can hit F5 or run from the menu bar to run your program. NB. You will be asked to save the program file before running so you can create a folder on your desktop and name it "MyfirstPythonCode." After that, save this statement exercise as statement.py in you folder and run your program.
This is what our program looks like; let's save it as average. py in our MyFirstPythonCode folder to keep our files organized.
- Run it!
print("This program calculates the average of two numbers") print("The numbers are 3 and 5 ") print("The average is: ", (3 + 5) / 2 ) output: This program calculates the average of two numbers The numbers are 3 and 5 The average is: 4.0 >>>
No comments:
Post a Comment