27 Aug Aurora Monday 18:30 Python Homework 20.08.24.
Question 1:
Modify the program we made in the class below, so you could convert decimal number into Hex(base 16 number):
from stack import *
def convBin(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(convBin(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: Number: 1258 Sample Output: 4EA
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.