Solution

High-Level Programming in Python

Problems to be Submitted (20 points)

  1. (4 points)

    1. One such example is x = 9, y = 3.
    2. One such example is x = 9, y = 4; Another is x = 6, y = 3.
    3. One such example is x = 1, y = 0; another is x = 5, y = 7.
    4. It must be that x in [2,3,4,5] and y <= 6.

    A pictoral representation of the various ranges is shown below.

  2. (4 points)

    The user entered 11 for a, and 14 for b.

  3. (4 points)

    The user entered 27 for a, and 23 for b.

  4. (4 points)

    Here is one possible solution.
    LOD X
    JZR IFCASE
    ELSECASELOD Z
    JMP BOTH
    IFCASELOD W
    BOTHADD Y
    STO Z
    STP

  5. (4 points)

    while J + K >= 25:
        J = J - K
    print J
    


Extra Credit

  1. (2 points)

    original = int(raw_input("Enter Decimal Value: "))
    base     = int(raw_input("Enter Desired Base: "))
    
    value = original
    answer = ""         # initially, no digits
    
    while value>0:
        quotient = value/base
        remainder = value%base
        answer = str(remainder)+answer
        value = quotient
    
    print "The decimal value", original, "is equivlaent to the value", answer, "in base", base
    

  2. (1 point)
    original = int(raw_input("Enter Decimal Value: "))
    base     = int(raw_input("Enter Desired Base: "))
    
    value = original
    answer = ""         # initially, no digits
    
    while value>0:
        quotient = value/base
        remainder = value%base
    
        if remainder<10:  # standard digit
            digit = str(remainder)
        else:
            digit = chr(ord("A")+(remainder-10))
            
        answer = digit+answer
        value = quotient
    
    print "The decimal value", original, "is equivlaent to the value", answer, "in base", base
    

Last modified: Saturday, 29 March 2008