CS 1064 Study Guide - Final Guide: Complex Number, Bacon

400 views4 pages
Daniel T. Eisert CS-1064: Introduction to Programming in Python Page 1 of 4
Daniel T. Eisert EXAM: May 02, 2018
CS-1064: Introduction to Python 12:20 P.M.
QUESTION
ANSWER
BASIC LITERALS: Print out each of the following
literal values on their own lines:
1. A positive integer (int)
2. A negative float (float)
3. A non-empty string (str)
4. A boolean (bool)
5. A None (None)
6. A non-empty list of integers (list)
7. A non-empty dictionary mapping strings to
integers (dict)
8. A tuple of two strings (tuple)
BASIC LITERALS:
print(5)
print(-5.0)
print("hi")
print(True)
print(None)
print([5, 3, 6])
print({"Test": 85, "Quiz": 100, "Homework": 98})
print(("hi", "bye"))
STRING CLEANING: Define a
function clean_string that consumes a string and
returns a new, cleaned string. To clean a string, you
will need to:
Strip whitespace from the end
Replace any plus signs with spaces
So, for example, the string " Hello+World " would
become "Hello World".
STRING CLEANING:
def clean_string(string):
string = string.replace("+", " ", 100)
string = string.strip()
return string
print(clean_string(" Hello+World"))
MORE DEMANDING: Define a
function make_demanding that consumes a string
and returns a new, more demanding string. To make
a string more demanding, add the string ", now!" to
the end. For example, the string "Pass the
butter" would become "Pass the butter, now!".
MORE DEMANDING:
def make_demanding(string):
ans = string + ", now!"
return ans
print(make_demanding("Pass the butter"))
IS SENTENCE: Define a function is_sentence that
consumes a string and returns a boolean indicating
whether the string ends in a ".", "?", or "!". For
example, the string "Hello?"would return True but
the string "Dog" would return False.
IS SENTENCE:
def is_sentence(sent):
punct = [".", "!", "?"]
return sent[-1:] in punct
print(is_sentence("Hey!"))
print(is_sentence("Hey."))
print(is_sentence("What?"))
print(is_sentence("Dog"))
print(is_sentence("What is your address?"))
print(is_sentence("It is rainy"))
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows page 1 of the document.
Unlock all 4 pages and 3 million more documents.

Already have an account? Log in

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