


































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



































Jake K. Carr
x = 0 while x < 4: print x x += 1 print " You ran the loop " + str ( x ) + " times. "
You ran the loop str ( x ) times.
for name in [ " Carter " , " Reagan " , " Bush " ]: print name + " was a U. S. president. "
Carter was a U. S. president. Reagan was a U. S. president. Bush was a U. S. president.
x = 2 multipliers = [1 ,2 ,3 ,4] for num in multipliers : print x * num
suits = [ ’ Spades ’ , ’ Clubs ’ , ’ Diamonds ’ , ’ Hearts ’] values = [ ’ Ace ’ , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , ’ Jack ’ , ’ Queen ’ , ’ King ’] for suit in suits : for value in values : print str ( value ) + " of " + str ( suit )
x = 2 if x == 1: print ’x is 1 ’
topic = ’ Geographic Information Systems ’ topic. count ( " i " )
2
folder = " C :/ Python27 / Lecture 2 " folder ’C :/ Python27 / Lecture 2 ’ folder = " C :\ Python27 \ Lecture 2 " folder ’C :\ Python27 \ Lecture 2 ’ folder = r " C :\ Python27 \ Lecture 2 " folder ’C :\ Python27 \ Lecture 2 ’
math. pow (2 ,4)
from math import * pow (2 ,4)
random. random () # Random float x , 0.0 <= x < 1.
random. uniform (1 , 10) # Random float x , 1.0 <= x < 10.
random. randint (1 , 10) # Random Integer from 1 to 10 2
random. choice ( ’ abcdefghij ’) # Choose a random element ’g ’
items = [1 , 2 , 3 , 4 , 5 , 6 , 7] random. shuffle ( items ) print items [2 , 3 , 5 , 6 , 1 , 7 , 4]
random. sample ( items ,3) # Choose 3 random elements from items [7 , 2 , 6]