Presentation is loading. Please wait.

Presentation is loading. Please wait.

Python Jim Eng Vote on class policy In lecture we discussed several ways in which you might show credits for content in the web pages.

Similar presentations


Presentation on theme: "Python Jim Eng Vote on class policy In lecture we discussed several ways in which you might show credits for content in the web pages."— Presentation transcript:

1 Python Jim Eng jimeng@umich.edu

2 Vote on class policy In lecture we discussed several ways in which you might show credits for content in the web pages you submit in this course. Please vote for the option below you most favor as the standard way in which credit for images (your own and from other sources) and other content should be shown in your assignments. 31 votes (out of 65)

3 A credit should be shown in the webpage with each image and with any text or other content from other sources. Credit for each image and for any text or other content from other sources should be shown as comments within the HTML file so they can be seen by viewing the HTML source. Credit for each image and for any text or other content from other sources should be shown in "alt" or "title" attributes within the HTML file so they can be seen by hovering over the element. Credit for each image and for any text or other content from other sources should be collected in a text file to be uploaded along with the other files when submitting an assignment.

4 A credit should be shown in the webpage with each image and with any text or other content from other sources. 13 Credit for each image and for any text or other content from other sources should be shown as comments within the HTML file so they can be seen by viewing the HTML source. 7 Credit for each image and for any text or other content from other sources should be shown in "alt" or "title" attributes within the HTML file so they can be seen by hovering over the element. 7 Credit for each image and for any text or other content from other sources should be collected in a text file to be uploaded along with the other files when submitting an assignment. 4

5 Patterns in programming - 1 Sequential steps Conditional steps Repeated steps Stored and reused steps

6 add 300 grams of flour add 100 ml of milk add an egg if altitude > 2000: add an egg add 30 grams of salt while there are too many lumps: beat mixture with a fork open and add provided flavor packet

7 add 300 grams of flour add 100 ml of milk add an egg if altitude > 2000: add an egg add 30 grams of salt while there are too many lumps: beat mixture with a fork open and add provided flavor packet

8 Patterns in programming - 2 Input Processing Output usf = input("Enter the US Floor Number: ") wf = usf - 1 print "Non-US Floor Number is ",wf

9

10 print "Your guess is", guess answer = 42 if guess < answer : print "Your guess is too low" if guess == answer : print "Congratulations!" if guess > answer : print "Your guess is too high"

11 print "Your guess is", guess answer = 42 if guess < answer : print "Your guess is too low" if guess == answer : print "Congratulations!" if guess > answer : print "Your guess is too high" Logical expressionsTrue or false?

12 print "Your guess is", guess answer = 42 if guess == answer : print "Good guess" else: print "Bad guess"

13 print “Bad guess” true false answer = 42 print “Good Guess” guess == answer

14 print "Your guess is", guess answer = 42 if guess == answer : print "Congratulations!" else: if guess < answer : print "Your guess is too low" else: print "Your guess is too high"

15 print "Your guess is", guess answer = 42 if guess == answer : print "Congratulations!" else: if guess < answer : print "Your guess is too low" else: print "Your guess is too high" Nested if-else statement

16 true false answer = 42 print “Congratulations” guess == answer print “Too High” true false print “Too low” guess < answer

17 print "Your guess is", guess answer = 42 if guess == answer : print "Congratulations!" elif guess < answer : print "Your guess is too low" else: print "Your guess is too high"

18 print “Congrats” true false answer = 42 guess == answer true false guess < answer print “Too low” print “Too high”

19 Variables A way of assigning a name for an area of memory A way of saving data temporarily Called a “variable” because contents can change Value of variable remains the same until it is changed or discarded

20 Assignment statements Sets the value of a variable Assign the value 42 into the variable named ‘answer’ Assignment operator (‘=’) not equality operator (‘==’) answer = 42 guess == answer

21 Elevator-floor conversion example Two variables Two assignment statements Input function Expression usf = input("Enter the US Floor Number: ") wf = usf - 1 print "Non-US Floor Number is ",wf

22 Expressions (usf - 1) is an expression (usf - 1) means retrieve the value of usf and subtract one from it oh, yeah, and save it in the variable wf wf = usf - 1

23 Elevator-floor conversion example usf = input("Enter the US Floor Number: ") print "Non-US Floor Number is ",(usf - 1) an expression can appear anywhere a variable can

24 Variable names in Python Must start with a letter or underscore Consist of letters, underscores, numbers Case-sensitive ( myVariable is not the same as myvariable ) Choose meaningful, mnemonic variable names

25 Reserved words and del from not whileas elif global or withassert else if pass yieldbreak except import printclass exec in raisecontinue finally is returndef for lambda try Have special meanings Cannot be used as variable names, function names, etc

26 Constants Values that never change usf = input("Enter the US Floor Number: ") wf = usf - 1 print "Non-US Floor Number is ",wf

27 print "Your guess is", guess answer = 42 msg = "" if guess == answer : msg = "Congratulations!" elif guess < answer : msg = "Your guess is too low" else: msg = "Your guess is too high" print msg

28 Strings - 1 txt = "guess=25" print txt[0] print txt[5] print txt[2:4] print txt[:5] print txt[6:] print txt[8]

29 Strings - 2 think = "happy" + "thoughts" print think think = "happy" + " " +"thoughts" print think

30 Defining functions - 1 def noParamsNoReturn():print "This function has no parameters and no return"returndef noParamsReturn(): print "This function has no parameters"return 123 noParamsNoReturn() print noParamsReturn()

31 Defining functions - 2 def paramsNoReturn(num):print "This function received a parameter of ",numreturndef paramsReturn(num): print "This function received a parameter of ",num return num * 5 paramsNoReturn(54) paramsReturn(20)

32 More examples Strings, String functions, Concatenation Types and Conversion Lists, List functions Integers and Floats Your own functions


Download ppt "Python Jim Eng Vote on class policy In lecture we discussed several ways in which you might show credits for content in the web pages."

Similar presentations


Ads by Google