6.00.1x lecture 2 notes

Upload: justin-collins

Post on 26-Feb-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/25/2019 6.00.1x Lecture 2 Notes

    1/32

    !"#$"%&&'($ *%($+%$,-

    .#%*/

    0,,1 % 2%3 4# 1,-5"'6, %*$#"'47&'5 -4,8- -+57

    47%4 5#&8+4," 5%( +-, 47,& 4# ,9,5+4, 8"#5,--

    !"#$"%&&'($ *%($+%$, 1,:(,- -3(4%9 %(1

    -,&%(;5- (,,1,1 4# 4"%(-*%4, #+" 5#&8+4%;#(%*

    '1,%- '(4# &,57%('5%* -4,8-

  • 7/25/2019 6.00.1x Lecture 2 Notes

    2/32

  • 7/25/2019 6.00.1x Lecture 2 Notes

    3/32

    7,5B," 5#(:"&- -3(4%9K -4%;5 -,&%(;5- 5#"",54

    A(4,"8",4," ?+-4 =#**#2- -,J+,(5, #= -'&8*, '(-4"+5;#(-

    @#+"5, 5#1,

    C#2 *,D,*

  • 7/25/2019 6.00.1x Lecture 2 Notes

    4/32

  • 7/25/2019 6.00.1x Lecture 2 Notes

    5/32

    7,5B,"

    compiled lang, code generally faster. we do the task of converting ahead of time

    challenges- if bug , difficult. too deep down to find what led to it.interpreted- little slower as we are doing conversion on the fly. easier to debug as we know what caused the

    bug

    (interpreted)

  • 7/25/2019 6.00.1x Lecture 2 Notes

    6/32

    !"#$%& ()%*)+,-

    !)%*)+, .%) -/)0(#1 0- + -2342&/2 %5

    !"#$%&'$( +&6 *'++,$!(

    728&09%&- 2:+;4+#26 +&6 /%,,+&6- 2

  • 7/25/2019 6.00.1x Lecture 2 Notes

    7/32

    @=A2/#-

    B# $2+)#? ()%*)+,- C0;; ,+&0(4;+#2 6+#+

    %=A2/#-

    D+/$ %=A2/# $+- + 023"#$+# 628&2- #$2 E0&6-%5 #$0&*- ()%*)+,- /+& 6% #% 0#

    @=A2/#- +)2F

    4*,.,5.0G2G /+&&%# =2 -4=60:06261? %)

    6'$7(*,.,5.0G2G $+:2 0)&+; -#)4/#4)2 #$+# /+& =2

    +//2--261

  • 7/25/2019 6.00.1x Lecture 2 Notes

    8/32

    H/+;+) %=A2/#-

    int I 4-26 #% )2()2-2 0*2)-? 2G*G? 5 %) 10082

    float I 4-26 #% )2()2-2 )2+; &4,=2)-? 2G*G? 3.14%) 27.0

    bool I 4-26 #% )2()2-2 J%%;2+& :+;42- True +&6False

    K$2 =40;# 0& !"#$%& 54&/9%& type )2#4)&- #$2 #"(2 %5+& %=A2/#

    >>> type(3)

    >>> type(3.0)

  • 7/25/2019 6.00.1x Lecture 2 Notes

    9/32

    D

  • 7/25/2019 6.00.1x Lecture 2 Notes

    10/32

    @(2)+#%)- %& int- +&6 float-

    i + j I -4, I 05 =%#$ +)2 int-? )2-4;# 0- int?

    05 20#$2) 0- float? )2-4;# 0- float

    i - j I 60N2)2&/2 i * j I ()%64/#

    i/j I 60:0-0%& I 05 =%#$ +)2 int-? )2-4;# 0- int?

    )2()2-2&9&* 34%92 C0#$%4# )2,+0&62)

    i%j I )2,+0&62)

    i**j I i)+0-26 #% #$2 (%C2) %5 j

  • 7/25/2019 6.00.1x Lecture 2 Notes

    11/32

    H%,2 -0,(;2 2

  • 7/25/2019 6.00.1x Lecture 2 Notes

    12/32

    !2)5%),0&* -0,(;2 %(2)+9%&-

    !+)2$2-2- 628&2 -4=Y/%,(4#+9%&- I /%,(;2#2#$2-2 #% *2# :+;42- =25%)2 2:+;4+9&* ;+)*2)2

  • 7/25/2019 6.00.1x Lecture 2 Notes

    13/32

    >%,(+)0-%& %(2)+#%)- %& int- +&6

    float-

    i > j I )2#4)&- True 05 -#)0/#;" *)2+#2)

    #$+&

    i >= j I )2#4)&- True 05 *)2+#2) #$+& %)234+;

    i < j

    i

  • 7/25/2019 6.00.1x Lecture 2 Notes

    14/32

    @(2)+#%)- %& bool-

    a and b 0- True 05 =%#$ +)2 True

    a or b 0- True 05 +# ;2+-# %&2 0- True

    not a 0- True 05 a 0- False\ 0# 0- False05 a 0- True

  • 7/25/2019 6.00.1x Lecture 2 Notes

    15/32

    K"(2 /%&:2)-0%&- .#"(2 /+-9&*1

    ]2 /+& %[2& /%&:2)# +& %=A2/# %5 %&2 #"(2 #%

    +&%#$2)? =" 4-0&* #$2 &+,2 %5 #$2 #"(2 +- +

    54&/9%&

    float(3) $+- #$2 :+;42 %5 3.0

    int(3.9) #)4&/+#2- #% 3

    round(x,ndigits)

  • 7/25/2019 6.00.1x Lecture 2 Notes

    16/32

    !"#$%& #&()* +, (-*./(01+)

    23"%& 4& 0() 4/".& (/-"./(/5 &6$/&**"+)*7 ". "*

    8*&,8% .+ 9":& )(#&* .+ :(%8&* +, &6$/&**"+)*7

    (); .+ -& (-%& .+ /&8*& .3+*& )(#&* ") $%(0&

    +, :(%8&*

    pi = 3.14159

    radius = 11.2

    area = pi * (radius**2)

  • 7/25/2019 6.00.1x Lecture 2 Notes

    17/32

  • 7/25/2019 6.00.1x Lecture 2 Notes

    18/32

    @3()9")9 -");")9*

    A(/"(-%& )(#&* 0() -&/&-+8);7 -5 "):+>")9 )&4(**"9)#&).* *.(.&).*?

    B+/ &6(#$%&7 ", 4& )+4&6&08.&Cradius = 11.2

    4& 9&. .3& ;"(9/(#*3+4) 3&/&?

    D+.& .3(. .3"* ;+&*)E.03()9& .3& :(%8&(**+0"(.&; 4".3 area

    after changing to 14.3 if we call area again, area still same as before.but if we execute area=pi*(radius**2) then we will get the new value

    14.3

  • 7/25/2019 6.00.1x Lecture 2 Notes

    19/32

    !"#$%&'(') "+,-&.%

    /- 01(( %-- 2'#3 415-)-#. 61#4% "7 &"28"9#4"+,-&.%

    :;- %128(-%. "7 .;-%- ')- %.)1#1.-)'(% "7 .38- %.)1#< &'# +- 0)1?-# 9%1#< %1#

  • 7/25/2019 6.00.1x Lecture 2 Notes

    20/32

    B8-)'.")% "# %.)1#

  • 7/25/2019 6.00.1x Lecture 2 Notes

    21/32

    KL.)'&M#< 8').% "7 %.)1#

  • 7/25/2019 6.00.1x Lecture 2 Notes

    22/32

    !"#$"%&' )#" '*"+,-'.

    /0+12 32 *%4 -5,2 26,"2''+#4' 7+"2*-15 -# %

    !5-0#4 +4-2","2-2" )8#" 26%&,12 9'+4$ %4

    +4-2"8%*2 '9*0 %' %4 :;

  • 7/25/2019 6.00.1x Lecture 2 Notes

    23/32

    !"#B+7+4$ +4,9-

    :8 32 %"2 $#+4$ -# 3"+-2 ,"#$"%&' #" '*"+,-'> 32

    3+11 4227 % 3%5 -# +4*#",#"%-2 +4,9- 8"#& %

    9'2"C

    /2 9'2 -02 !5-0#4 894*@#4 raw_input> %'

    +4D

    >>> name = raw_input(Enter your name: )

    Enter your name: Eric Grimson

    >>> print(Are you + name + ?)

    Are you Eric Grimson?

    use typecasting to get int type input. ex. int(raw_input('Enter a no: '))

  • 7/25/2019 6.00.1x Lecture 2 Notes

    24/32

    E#&2 '+&,12 *#72

    F42 *%4 9'2 B%"+%G12 4%&2' %45302"2 5#9

    &+$0- 9'2 -02 26,"2''+#4 30#'2 B%192 +- 0#17'

    >>> myString = Too much

    >>> weather = snow

    >>> print(myString + +

    weather)

    Too much snow

  • 7/25/2019 6.00.1x Lecture 2 Notes

    25/32

    H '-"%+$0- 1+42 ,"#$"%&

    E9,,#'2 32 -5,2 -02 8#11#3+4$ +4-# % ?12> %47 1#%7 +- +4-# %!5-0#4 :;

  • 7/25/2019 6.00.1x Lecture 2 Notes

    26/32

    E#&2 #G'2"B%@#4'

    K#&&24-' %,,2%" %L2" % M

    I02'2 %"2 B2"5 B%19%G12> %' -025 021, % 9'2"9472"'-%47 72*+'+#4' -02 ,"#$"%&&2" 0%' &%72 +4

    *"2%@4$ -02 ,"#$"%& /211 *#&&24-27 *#72 '0#917 G2 B2"5 "2%7%G12 G5 %

    9'2"

    H '-"%+$0- 1+42 ,"#$"%& '+&,15 262*9-2' 2%*0

    '-%-2&24- +4 #"72"> 3+-0 4# B%"+%@#4 +4 #"72" N#'- ,"#$"%&' "2O9+"2 "2 '#,0+'@*%-27 P#3

    *#4-"#1

  • 7/25/2019 6.00.1x Lecture 2 Notes

    27/32

    !"#$%&'$( *"+("#,-

    .&/ -',*0/-1 2"#$%&'$(-1#1/,/$1 '- # !"#$%&"#'(

    3 1/-1 4/5*"/--'+$ 1

    /6#07#1/- 1+ True +"False8

    3 20+%9 +: %+;/ 1+ /5/%71/': 1&/ 1/-1 '- True

    3$ +*

  • 7/25/2019 6.00.1x Lecture 2 Notes

    28/32

    3 -',*0/ /5#,*0/

    x = int(raw_input('Enter an integer: '))

    if x%2 == 0:

    print()

    print('Even')

    else:

    print()

    print('Odd')

    print(Done with conditional')

    notice the indentation

    indentation matters

  • 7/25/2019 6.00.1x Lecture 2 Notes

    29/32

    =+,/ +2-/"6#/"/ '$;/$1/;A '1

    >+70; 2/ /5/%71/; #- *#"1 +: 1&/ else 20+%9 +: %+;/

    @+1/ &+> 1&'- '$;/$1#

  • 7/25/2019 6.00.1x Lecture 2 Notes

    30/32

    E/ %#$ / $/-1/; %+$;'

  • 7/25/2019 6.00.1x Lecture 2 Notes

    31/32

    3$; >/ %#$ 7-/ %+,*+7$; !++0/#$-

    if x < y and x < z:

    print('x is least)

    elif y < z:

    print('y is least)

    else:

    print('z is least)

  • 7/25/2019 6.00.1x Lecture 2 Notes

    32/32

    E / >/ #;;/;F

    !"#$%&'$( *"+("#,- #00+> 7- 1+ ,#9/ %&+'%/-

    #$; ;+ ;'G/"/$1 1&'$(-

    !71 -