TORONTO KIDS COMPUTER CLUB | Friday 17:00 Python Practice 21.01.15.
18943
post-template-default,single,single-post,postid-18943,single-format-standard,ajax_fade,page_not_loaded,,qode-theme-ver-7.6.2,wpb-js-composer js-comp-ver-6.8.0,vc_responsive

Friday 17:00 Python Practice 21.01.15.

20 Jan Friday 17:00 Python Practice 21.01.15.

Question 1:
Modify the program we made in the class below, so you could convert decimal number into any base number between Binary(base 2 number ) to Hex(base 16 number):

from stack import *
def d2b(num):
    s = Stack()
    while num > 0:
        r = num % 2
        s.push(r)
        num = num // 2
    binResult = ''
    while s.isEmpty() == False:
        binResult += str(s.pop())
    return binResult

while True:
    print(d2b(int(input('Number: '))))

remember the hex number is consist of 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F

Sample Input 1:
Number: 1258, 16

Sample Output 1:
4EA

Sample Input 2:
Number: 1258, 8

Sample Output 2:
2352

Question 2:

We have learned infix, prefix and postfix, please write the missing prefix and postfix in the table blow:

infix prefix postfix
A+B +AB AB+
A+B*C +A*BC ABC*+
(A+B)*C *+ABC AB+C*
A+B*C+D ++A*BCD ABC*+D+
(A+B)*(C+D)    
A*B+C*D    
A+B+C+D

No Comments

Sorry, the comment form is closed at this time.