Chp 9 Activity, correct the code

PLEASE BRING HEADPHONES TO MON’S CLASS AND BEYOND AS WE WILL BE STARTING EARSKETCH AND WE DON’T WANT TO BE DISRUPTIVE TO OTHERS IN THE CLASS.

Instead of the quiz, answer the following questions below. Copy and past the code into your wing IDE and try to fix the mistakes. Then, copy and paste your corrected code into a new MS Word or Google Docs document and save it on the server when done.

  1. Correct the following code: (Don’t let it print out the word “None”)
    def sum(a, b, c):
    print(a + b + c)
    print(sum(10, 11, 12))
  2. Correct the following code: (x should increase by one, but it doesn’t.)
    def increase(x):
    return x + 1
    x = 10
    print("X is", x, " I will now increase x." )
    increase(x)
    print("X is now", x)
  3. Correct the following code:
    def print_hello:
    print("Hello")
    print_hello()
  4. Correct the following code:
    def count_to_ten():
    for i in range[10]:
    print(i)
    count_to_ten()
  5. Correct the following code:
    def sum_list(list):
    for i in list:
    sum = i
    return sum
    list = [45, 2, 10, -5, 100]
    print(sum_list(list))
  6. Correct the following code: (This almost reverses the string. What is wrong?)
    def reverse(text):
    result = ""
    text_length = len(text)
    for i in range(text_length):
    result = result + text[i * -1]
    return result
    text = "Programming is the coolest thing ever."
    print(reverse(text))
  7. Correct the following code:
    def get_user_choice():
    while True:
    command = input("Command: ")
    if command = f or command = m or command = s or command = d or command = q:
    return command
    print("Hey, that's not a command. Here are your options:" )
    print("f - Full speed ahead")
    print("m - Moderate speed")
    print("s - Status")
    print("d - Drink")
    print("q - Quit")
    user_command = get_user_choice()
    print("You entered:", user_command)
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s