CSC108H1 Study Guide - Midterm Guide: Empty String, Standard Streams, Substring

71 views7 pages
7 Mar 2019
School
Course
Professor
yifanyang and 39659 others unlocked
CSC108H1 Full Course Notes
21
CSC108H1 Full Course Notes
Verified Note
21 documents

Document Summary

Convert the following for loop into a while loop. string_list is a non-zero length list that contains only strings. lower_list is an initially empty list. for elt in string_list: if elt. is_upper(): lower_list. append(elt. lower()) Solution: i = 0 while i < len(string_list): if string_list[i]. is_upper(): lower_list. append(string_list[i]. lower()) i += 1. Solution: ret_list = [] i = 2 while i < end: ret_list. append(i) if "*" in in_list[i]: ret_list[-1] = ret_list[-1]**2 i += 4. Convert the following while loop into a for loop. You code should be written so that the return statement does not need to be altered. #first element after the 15th "***" return j. Rewrite this block of code so that there are no indents. x is an integer. [4 marks] if (x % 2) == 0: if (x < 50): return true else: return false else: if (x < 50): return false else: return false. Solution: return ((x % 2) == 0) and (x < 50)

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers

Related Documents