iteration announcements return return statements
play

Iteration Announcements Return Return Statements 4 Return - PowerPoint PPT Presentation

Iteration Announcements Return Return Statements 4 Return Statements A return statement completes the evaluation of a call expression and provides its value: 4 Return Statements A return statement completes the evaluation of a call


  1. Iteration

  2. Announcements

  3. Return

  4. Return Statements � 4

  5. Return Statements A return statement completes the evaluation of a call expression and provides its value: � 4

  6. Return Statements A return statement completes the evaluation of a call expression and provides its value: f(x) for user-defined function f : switch to a new environment; execute f's body � 4

  7. Return Statements A return statement completes the evaluation of a call expression and provides its value: f(x) for user-defined function f : switch to a new environment; execute f's body return statement within f : switch back to the previous environment; f(x) now has a value � 4

  8. Return Statements A return statement completes the evaluation of a call expression and provides its value: f(x) for user-defined function f : switch to a new environment; execute f's body return statement within f : switch back to the previous environment; f(x) now has a value Only one return statement is ever executed while executing the body of a function � 4

  9. Return Statements A return statement completes the evaluation of a call expression and provides its value: f(x) for user-defined function f : switch to a new environment; execute f's body return statement within f : switch back to the previous environment; f(x) now has a value Only one return statement is ever executed while executing the body of a function def end (n, d): """Print the final digits of N in reverse order until D is found. >>> end(34567, 5) 7 6 5 """ � 4

  10. Return Statements A return statement completes the evaluation of a call expression and provides its value: f(x) for user-defined function f : switch to a new environment; execute f's body return statement within f : switch back to the previous environment; f(x) now has a value Only one return statement is ever executed while executing the body of a function def end (n, d): """Print the final digits of N in reverse order until D is found. >>> end(34567, 5) 7 6 5 """ while n > 0 : last, n = n % 10 , n // 10 print(last) � 4

  11. Return Statements A return statement completes the evaluation of a call expression and provides its value: f(x) for user-defined function f : switch to a new environment; execute f's body return statement within f : switch back to the previous environment; f(x) now has a value Only one return statement is ever executed while executing the body of a function def end (n, d): """Print the final digits of N in reverse order until D is found. >>> end(34567, 5) 7 6 5 """ while n > 0 : last, n = n % 10 , n // 10 print(last) if d == last: return None � 4

  12. Return Statements A return statement completes the evaluation of a call expression and provides its value: f(x) for user-defined function f : switch to a new environment; execute f's body return statement within f : switch back to the previous environment; f(x) now has a value Only one return statement is ever executed while executing the body of a function def end (n, d): """Print the final digits of N in reverse order until D is found. >>> end(34567, 5) 7 6 5 """ while n > 0 : last, n = n % 10 , n // 10 print(last) if d == last: return None (Demo) � 4

  13. Self-Reference (Demo)

  14. Returning a Function Using Its Own Name � 6 http://pythontutor.com/composingprograms.html#code=def%20print_all%28k%29%3A%0A%20%20%20%20print%28k%29%0A%20%20%20%20return%20print_all%0A%20%20%20%20%0Aprint_all%281%29%283%29%285%29&cumulative=true&curInstr=0&mode=display&origin=composingprograms.js&py=3&rawInputLstJSON=%5B%5D http://pythontutor.com/composingprograms.html#code=def%20print_sums%28n%29%3A%0A%20%20%20%20print%28n%29%0A%20%20%20%20def%20next_sum%28k%29%3A%0A%20%20%20%20%20%20%20%20return%20print_sums%28n%2Bk%29%0A%20%20%20%20return%20next_sum%0A%0Aprint_sums%281%29%283%29%285%29&cumulative=true&curInstr=0&mode=display&origin=composingprograms.js&py=3&rawInputLstJSON=%5B%5D

  15. Control

  16. If Statements and Call Expressions Let's try to write a function that does the same thing as an if statement. � 8

  17. If Statements and Call Expressions Let's try to write a function that does the same thing as an if statement. if __________: _________ else: _________ � 8

  18. If Statements and Call Expressions Let's try to write a function that does the same thing as an if statement. if __________: _________ else: _________ Execution Rule for Conditional Statements: � 8

  19. If Statements and Call Expressions Let's try to write a function that does the same thing as an if statement. if __________: _________ else: _________ Execution Rule for Conditional Statements: Each clause is considered in order. � 8

  20. If Statements and Call Expressions Let's try to write a function that does the same thing as an if statement. if __________: _________ else: _________ Execution Rule for Conditional Statements: Each clause is considered in order. 1. Evaluate the header's expression (if present). � 8

  21. If Statements and Call Expressions Let's try to write a function that does the same thing as an if statement. if __________: _________ else: _________ Execution Rule for Conditional Statements: Each clause is considered in order. 1. Evaluate the header's expression (if present). 2. If it is a true value (or an else header), 
 execute the suite & skip the remaining clauses. � 8

  22. If Statements and Call Expressions Let's try to write a function that does the same thing as an if statement. if __________: "if" clause _________ else: _________ Execution Rule for Conditional Statements: Each clause is considered in order. 1. Evaluate the header's expression (if present). 2. If it is a true value (or an else header), 
 execute the suite & skip the remaining clauses. � 8

  23. If Statements and Call Expressions Let's try to write a function that does the same thing as an if statement. if __________: "if" clause _________ else: "else" clause _________ Execution Rule for Conditional Statements: Each clause is considered in order. 1. Evaluate the header's expression (if present). 2. If it is a true value (or an else header), 
 execute the suite & skip the remaining clauses. � 8

  24. If Statements and Call Expressions Let's try to write a function that does the same thing as an if statement. "if" header if __________: expression "if" clause _________ else: "else" clause _________ Execution Rule for Conditional Statements: Each clause is considered in order. 1. Evaluate the header's expression (if present). 2. If it is a true value (or an else header), 
 execute the suite & skip the remaining clauses. � 8

  25. If Statements and Call Expressions Let's try to write a function that does the same thing as an if statement. "if" header if __________: expression "if" clause _________ "if" suite else: "else" clause _________ Execution Rule for Conditional Statements: Each clause is considered in order. 1. Evaluate the header's expression (if present). 2. If it is a true value (or an else header), 
 execute the suite & skip the remaining clauses. � 8

  26. If Statements and Call Expressions Let's try to write a function that does the same thing as an if statement. "if" header if __________: expression "if" clause _________ "if" suite else: "else" "else" suite clause _________ Execution Rule for Conditional Statements: Each clause is considered in order. 1. Evaluate the header's expression (if present). 2. If it is a true value (or an else header), 
 execute the suite & skip the remaining clauses. � 8

  27. If Statements and Call Expressions Let's try to write a function that does the same thing as an if statement. "if" header if __________: expression "if" clause _________ "if" suite else: "else" "else" suite clause _________ Execution Rule for Conditional Statements: Each clause is considered in order. 1. Evaluate the header's expression (if present). 2. If it is a true value (or an else header), 
 execute the suite & skip the remaining clauses. � 8

  28. If Statements and Call Expressions Let's try to write a function that does the same thing as an if statement. "if" header if __________: expression "if" clause _________ "if" suite if_(________, ________, ________) else: "else" "else" suite clause _________ Execution Rule for Conditional Statements: Each clause is considered in order. 1. Evaluate the header's expression (if present). 2. If it is a true value (or an else header), 
 execute the suite & skip the remaining clauses. � 8

  29. If Statements and Call Expressions Let's try to write a function that does the same thing as an if statement. "if" header if __________: expression "if" clause _________ "if" suite if_(________, ________, ________) else: "else" "if" header "else" suite clause expression _________ Execution Rule for Conditional Statements: Each clause is considered in order. 1. Evaluate the header's expression (if present). 2. If it is a true value (or an else header), 
 execute the suite & skip the remaining clauses. � 8

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend