184_notes:python_syntax

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
184_notes:python_syntax [2018/06/04 14:58] dmcpadden184_notes:python_syntax [2020/08/24 19:31] (current) dmcpadden
Line 1: Line 1:
 +/*[[184_notes:using_python|Previous Page: Making Models with VPython]]*/
 +
 ===== Common Commands and Tips for Python ===== ===== Common Commands and Tips for Python =====
 In this class, we are often going to use VPython to create computational models, which will serve as a powerful tool to help us create visualizations and apply the ideas in this course to more real-world contexts. Below are some of the common Python commands that we will use in this course and some coding tips compiled by previous EMP-Cubed students. (Note: we do not expect you to have any coding experience prior to this course, and we will not expect you to write a program from scratch. We will primarily be asking you to interpret chunks of code with your group members and adjust/modify pieces of code that you will be given.) In this class, we are often going to use VPython to create computational models, which will serve as a powerful tool to help us create visualizations and apply the ideas in this course to more real-world contexts. Below are some of the common Python commands that we will use in this course and some coding tips compiled by previous EMP-Cubed students. (Note: we do not expect you to have any coding experience prior to this course, and we will not expect you to write a program from scratch. We will primarily be asking you to interpret chunks of code with your group members and adjust/modify pieces of code that you will be given.)
Line 37: Line 39:
 position2=vec(2,1,0) position2=vec(2,1,0)
 separation=position2-position1  #This will give separation=vec(-1,-3,-5) separation=position2-position1  #This will give separation=vec(-1,-3,-5)
-testing=separation-4 #This will give and error+testing=separation-4 #This will give an error
 </code> </code>
   * **Vector magnitude** - the "mag()" command will calculate the [[184_notes:math_review#Vector_Notation|magnitude of any vector]].    * **Vector magnitude** - the "mag()" command will calculate the [[184_notes:math_review#Vector_Notation|magnitude of any vector]]. 
Line 53: Line 55:
 A=vec(1,2,3) A=vec(1,2,3)
 B=vec(4,5,6) B=vec(4,5,6)
-AB=dot(A,B)+AB=dot(A,B)  #This will calculate (1*4)+(2*5)+(3*6) 
 +print(AB)  #This will print out 32
 </code> </code>
   * **Cross Product** - the cross product is another way to [[184_notes:math_review#Vector Multiplication|multiply two vectors]]. Python has this command already programmed in:   * **Cross Product** - the cross product is another way to [[184_notes:math_review#Vector Multiplication|multiply two vectors]]. Python has this command already programmed in:
Line 59: Line 62:
 C=vec(5,6,7) C=vec(5,6,7)
 D=vec(3,2,1) D=vec(3,2,1)
-CD=cross(C,D)+CD=cross(C,D)  #This will calculate (6*1-2*7)i-hat - (5*1-7*2)j-hat + (5*2-6*3)k-hat 
 +print(CD)  #This will print out the vector (-8, 9, -8)
 </code> </code>
  • 184_notes/python_syntax.1528124338.txt.gz
  • Last modified: 2018/06/04 14:58
  • by dmcpadden