Try a few commands in the interactive shell (aka Console).
is the prompt, meaning Python is ready for a command,
means it's a line continuation (i.e., Python is waiting for you to finish the statement) and a line without anything in front of it is generally the response from the interpreter.
In the shell (console) you can use the up arrow and down arrow keys to revisit commands you typed previously. Use the up arrow key to get your previous statement and then edit it to get the area of the floor of the field house bubble if we assume that the radius is 100 feet.
Calculate how many students could fit standing up in the field house. Discuss with your neighbor what assumptions you made to get this calculation.
When you're ready to move on, copy and paste your interactive session into a new window in the Spyder editor (select "New File" from the File menu, and erase the initial text). Don't copy more than a page. Put your name at the top. Then save this page as a text file in your assignment1 folder since you'll be submitting it. To do so, select "Save as" from the File menu, Save as type "Text files (*.txt)", and save your file as "problem1.txt" in your assignment1 folder.
So far, we've only been interacting with the Python shell. This is good for some situations, but eventually, you're going to want to write longer programs that you can edit easily and persist when you quit Spyder.
Each line you enter in the file will be executed in the shell as if you typed it. For example, enter "22/7" in the file. You can run your file by clicking the green arrow.
When you do this, you'll notice that your program gets executed by the Python shell in the bottom right. Most likely, your program won't show anything in the shell window. Make sure you understand why your program displays what it does! Discuss the output with your neighbor.
When you are running a program (vs. interacting with the shell) the intermediate results are not shown. Instead, if you want things to be displayed you need to use the print function. You can print anything that represents a value, for example:
print(10) # printing a number print(22/7) # printing another number pi = 22/7 # assign 22/7 to pi print(pi) # print out what is stored in pi print("Hello computer user") # printing a string
Add a few print statements to your program and run it again. You should now see some results printed out.
Remember the basic structure for defining a function is:
def function_name ( parameters ) :
return something # not all functions will have return statements
Remember that the way that Python can tell what is part of the function is based on the indenting.
Remember, we can print anything that represents a value:
This statement has multiple parts. circle_area(25) calls our defined circle_area, which, in turn, will execute the statements inside your defined function. When it returns, that value will then be printed by the print function.
After you've run your program, you can still interact with the interpreter (bottom right). For example, you can type:
>>> circle_area(12.4) 483.2457142857143
What's in your file so far:
At this point, you program/file should have some statements at the top, followed by some print statements and then your definition for circle_area. Put comments above each of these sections so they are clearly delimited and then move on to the next section.
For the last part of this assignment, you will write some functions of your own in the same file created for the previous section.
You're going to do a semester abroad in Europe and have decided to write a few functions that will help you out with some common questions you might find yourself asking while you're there.
>>> euros_to_dollars(13.5) 15.24285
(Note: depending on the exchange rate you use, your value will be slightly different)
Make sure that you are using the return statement and not printing the answer in your function. In particular, try running the following and make sure you get something similar:
>>> dollars = euros_to_dollars(13.5) >>> print(dollars) 15.24285
>>> welcome() Willkommen
Remember that you can create functions with zero parameters. To call a function without any parameters, you still need to put the parentheses at the end.
>>> kilometers_to_miles(100) 62.137
>>> mpg_from_metric(400, 30) 31.358472666666668
|Submit each file using the digital submission page by the beginning of your class section on Wed 2/22.|
|Comments and code style||3|
|Total||23 + 2|