# [ ] define and call a function short_rhyme() that prints a 2 line rhyme
def short_rhyme():
print("hey diddle diddle the cat and the fiddle the cow jumped over the moon")
print("hey diddle diddle the cat and the fiddle the cow jumped over the moon")
short_rhyme()
hey diddle diddle the cat and the fiddle the cow jumped over the moon
hey diddle diddle the cat and the fiddle the cow jumped over the moon
# [ ] define (def) a simple function: title_it() and call the function
# - has a string parameter: msg
# - prints msg in Title Case
def title_it(msg):
return msg.title()
title_it("east rowan")
# [ ] get user input with prompt "what is the title?"
# [ ] call title_it() using input for the string argument
def title_it():
print(input("What is the title?").title())
title_it()
What Time Is It
# [ ] define title_it_rtn() which returns a titled string instead of printing
# [ ] call title_it_rtn() using input for the string argument and print the result
def title_it_rtn():
return input("what to title?").title()
print(title_it_rtn())
The Time
# [ ] create, call and test bookstore() function
book_entry=title_it_rtn()
price_entry=input("Book cost")
def bookstore(book,price):
print("The book",book,"costs $"+price)
bookstore(book_entry,price_entry)
The book The Big Red Dog costs $5.99
def make_greeting(name, greeting = "Hello"):
return (greeting + " " + name + "!")
def get_name():
name_entry = input("enter a name: ")
return name_entry
def get_greeting():
greeting_entry = input("enter a greeting: ")
return greeting_entry
# get name and greeting, send to make_greeting
print(make_greeting(get_name(), get_greeting()))
hi braeden!
# The following program displays the double of a number
# Fix the error/s in the program so the correct answer is displayed
# Remember to explain what the error was and how you fixed it and document the function
def double(num):
answer = num * 2
return answer
a=double(6)
print(a)
12
# [ ] The program below converts a length from Centimeters to Inches, Feet, Yards, and Miles
# Complete the functions cent2inches, cent2feet, cent2yards, cent2miles so they all return the expected result and display the result
def cent2inches(length):
result=length*0.393701
return result
print(cent2inches(1))
def cent2feet(length):
result=length*0.0328084
return result
print(cent2feet(1))
def cent2yards(length):
result=length*0.0109361
return result
print(cent2yards(1))
def cent2miles(length):
result=length*6.2137e-6
return result
print(cent2miles(1))
0.393701
0.0328084
0.0109361
6.2137e-06
# [ ] Complete the function `formatted_phone()` so it displays the PHONE number as 777-248-3940
PHONE = "7895550153"
def phone_format(n):
return format(int(n[:-1]), ",").replace(",", "-") + n[-1]
phone_format(PHONE)
# [ ] In the following program, the function change_x should change the value stored in x from 5 to 7
# modify the function so the value of x is changed from within the function
x = 5
def change_x():
global x
x = 7
print("Before change x =", x) # should be 5
change_x()
print("After change x =", x) # should be 7
Before change x = 5
After change x = 7