{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Exam 1- 2012

# hello printy if y goodbye printgoodbye j a4 if

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: (g) for k in range(5): print(2 * k) CS 115 Exam 1, Fall 2012 Page 3 of 8 (h) x = 1 for i in range(3): x=x*2 print(x) (i) y = "hello" if y != "hello": print(y) if y != "goodbye": print("goodbye") (j) a=4 if a < 0: print("brownies") elif a < 5: print("cookies") else: print("cake") CS 115 Exam 1, Fall 2012 Page 4 of 8 Problem 2: 30 points. Write snippets of code to do the following. Your code should only print the requested output. You will lose points for printing additional output. You can assume that all your snippets are enclosed within a main function and that any necessary libraries have been imported. You only need to write the specific lines of code that accomplish each task. (a) Ask the user to enter the amount of gas they bought (in gallons). Assume the user enters a valid positive number. Then print that amount in liters. Use 1 gallon = 3.78541 liters to do your conversion. (b) As...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online