COSI 2a Lecture Notes - Lecture 4: Iterator, Square Root

48 views6 pages

Document Summary

Comparison operators xy x>=y x!=y. And/or/not operators is_in_highschool = ((9 <= grade) and (grade <= 12)) can_go_to_prom = is_in_highschool and has_a_date can_sleep_in = is_weekend or is_holiday. Voting age write a function can_vote(age) which returns true if a us citizen of the specified can vote. ie. if they are at least 18 years old. For example, can_vote(18) --> true can_vote(17) --> false can_vote(61) --> true can_vote(1) --> false. Grading write a method gets_b(score) which returns true if a person with a given score gets a b, that is their grade is at least 80 and less than 90. e. g. gets_b(100) --> false gets_b(82) --> true. Write a method abs_value(x) which returns the absolute value of x. So if x is positive it just returns x; if x is negative it returns -x. e. g. abs_value(5) --> 5 abs_value(-3) --> 3. Do this using an if statement to test if x is positive or not

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents