16 Mar PMCA Sunday 10:00 Practice -03.14
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 |
Sorry, the comment form is closed at this time.