Intro to Python

Lab 1:  Python

1.  Python Shell,  Calculator

2.  Learning Python Resources and IDLE

3.  Book Python Chaos example

              # File: chaos.py

                   def main():
                  
print "This program illustrates a chaotic function"

                   x = input("Enter a number between 0 and 1: ")

                   for i in range(10):
                             
x = 3.9 * x * (1 - x)
                             
print x


                  
main()

          -copy

          -modify

    4.  Print options

5.  Getting input:

          -input

          -raw_input

6.  celsius = input("What is the Celsius temperature? ")
    fahrenheit = 9.0 / 5.0 * celsius + 32
    print "The temperature is", fahrenheit, "degrees Fahrenheit."

    Challenge:  Input Fahrenheit and output Celcius

   Challenge:  Input kilometers and output miles (.62)

 print "This program calculates the future value of a 10-year invest"
 principal = input("Enter the initial principal: ")
 apr = input("Enter the annual interest rate: ")
 for i in range(10):
        principal = principal * (1 + apr)
 print "The value in 10 years is:", principal

         

7.  Form Letter Program:

          Write a program to get 5 inputs from the user.  Then use these 5 inputs to print out a form letter using these inputs.   Next CS Lab period, turn in a copy of your Python Code plus 2 different outputs of your code in action

Lab 1, Visual Python:

1.  A simple sphere

2.  A bit about Objects

          -nothing new.. organization and reusability

          -idea same as chips vs transistors...
            assemble software

3.  Making a Projectile

4.  Visual Python Tutorial

d

d

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

from visual import *

ball = sphere(pos=(-6,.1,0), color=color.blue,radius=.4)

ball.velocity = vector(6,10,0)

wind=vector(-1,0,1)

d=.01

while ball.pos.y>=0:

    rate(50)

    print ball.pos.x,ball.pos.y,ball.pos.z

    ball.velocity.y = ball.velocity.y-9.8*d

    ball.velocity = ball.velocity+wind*d

    ball.pos = ball.pos + ball.velocity*d