Wednesday, January 11, 2017

Blog 39

What do these programs print? What is significant about the output of the two programs?

Program 1

list=[1, 2, 3, 1, "hi", "hello"]
list.sort()
print list
list.reverse()
print list



Program 2

list=[1, 2, 3, 1, "hi", "hello"]
list.reverse()
print list
list.sort()
print list

16 comments:

  1. [1, 1, 2, 3, 'hello', 'hi']
    ['hi', 'hello', 3, 2, 1, 1]
    ['hello', 'hi', 1, 3, 2, 1]
    [1, 1, 2, 3, 'hello', 'hi']

    jonathan

    ReplyDelete
  2. 1,1,2,3,hi,hello
    hello,hi,3,2,1,1

    hello,hi,1,3,2,1
    hi,hello,1,1,2,3
    Charlie Lin

    ReplyDelete
  3. 1
    1 1 2 3 hello hi
    hi hello 3 2 1 1

    2
    hello hi 1 3 2 1
    1 1 2 3 hello hi

    Program 1 sorts it and then reverses the sorted list
    Program 2 reverses the list's original order and then sorts it

    ReplyDelete
  4. ["hello","hi",1,3,2,1]
    ["hi","hello",1,1,2,3]
    ---Lux lei

    ReplyDelete
  5. 1.
    [1, 1, 2, 3, "hello", "hi"]
    ["hi", "hello", 3, 2, 1, 1]

    2.
    ["hello", "hi", 1, 3, 2, 1]
    [1, 1, 2, 3, "hello", "hi"]

    The order of the sort and reverse commands changes the order of the second print in each function.

    Josh Lee

    ReplyDelete
  6. Program 1:
    [1,1,2,3,"hello", "hi"]
    ["hi","hello",3,2,1,1]

    Program 2:
    ["hello","hi",1,3,2,1]
    [1,1,2,3,"hello","hi"]

    Program 1 ends with list equaling the original values being ordered in reverse python order. Program 2 ends with the original values in python order. The sort at the end of Program 2 negates the reverse before it.
    -Katelyn

    ReplyDelete
  7. [1, 1, 2, 3, 'hello', 'hi']
    ['hi', 'hello', 3, 2, 1, 1]
    ['hello', 'hi', 1, 3, 2, 1]
    [1, 1, 2, 3, 'hello', 'hi']
    they sorted and reversed the lists in a different order

    jonathan

    ReplyDelete
  8. program 1
    1,1,2,3,"hello","hi"
    "hi","hello",3,2,1,1
    program 2
    "hello","hi",1,3,2,1
    1,1,2,3,"hello","hi"
    They are significant, They are different because the first one is sorted then reverse, but the second one is reverse then sorted which undoes the reverse into a sorted order
    -Sean

    ReplyDelete
  9. Program 1
    [1,1,2,3,"hello","hi"]
    ["hi","hello",3,2,1,1]
    Program 2
    ["hello","hi",1,3,2,1]
    [1,1,2,3,"hello","hi"]
    reverse doesn't sort on its own
    _Ben

    ReplyDelete
  10. [1,1,2,3,"hi","hello"]
    ["hello","hi",3,2,1,1]

    ["hello","hi",1,3,2,1]
    ["hello","hi",3,2,1,1]

    -Gary

    ReplyDelete
  11. Program 1
    1,1,2,3, "hello", "hi"
    "hi", "hello", 3,2,1,1

    Program 2
    "hello", "hi", 1,3,2,1
    1,1,2,3, "hello", "hi"
    They're significant because the last line in program 2 is the first line in program 1.

    Alex Haston

    ReplyDelete
  12. Prog 1:
    1,1, 2, 3, ,"hello", "hi"
    "hi", "hello", 3, 2, 1, 1

    Prog 2:
    "Hello","hi",1,3,2,1
    1,1, 2, 3, ,"hello", "hi"

    These two are different because in the first we sorted the list then reversed it where in the second one we reversed it first then sorted. This causes the second program to be opposite of what the first program is, and remding the reverse command useless.
    -Joe Haj

    ReplyDelete
  13. [1,1,2,3,"hello","hi"]
    ["hi","hello",3,2,1,1]

    ~Travis Vonheeder

    ReplyDelete
  14. Chris VanYe
    [1,1,2,3,"hello","hi"]
    ["hi","hello",3,2,1,1]

    ["hello","hi",1,3,2,1]
    [1,1,2,3,"hello","hi"]

    when you sort ad then reverse, it prints the reverse order. if you reverse and then sort, the sort undoes anything that the reverse did when it sorts it.

    ReplyDelete
  15. ["hi", "hello", 3, 2, 1, 1]

    [1, 1, 2, 3, "hello", "hi"]

    The significant difference is Program 1 is in descending sorted order and Program 2 is in ascending sorted order.

    - Abby Peterson

    ReplyDelete
  16. [1, 1, 2, 3, 'hello', 'hi']
    ['hi', 'hello', 3, 2, 1, 1]
    ['hello', 'hi', 1, 3, 2, 1]
    [1, 1, 2, 3, 'hello', 'hi']

    -Owen Luther

    ReplyDelete