calculator (operating on any number system) with the following operations:
- adding positive and negative numbers (i.e. the following combinations "-1 + 2", "-1 + -2", "1 + 2" and "1 + -2" work),
- subtraction of positive numbers with the result greater than or equal to zero (A - B> = 0),
- very simple multiplication of positive and negative numbers ,
- fast multiplication of positive and negative numbers.
- adding positive and negative numbers (i.e. the following combinations "-1 + 2", "-1 + -2", "1 + 2" and "1 + -2" work),
- subtraction of positive numbers with the result greater than or equal to zero (A - B> = 0),
- very simple multiplication of positive and negative numbers ,
- fast multiplication of positive and negative numbers.
maska = "" for i in range(ord('0'), ord('9') + 1): maska += chr(i) for i in range(ord('A'), ord('Z') + 1): maska += chr(i) def konwersja(liczba, dlugosc): return ('0' * (dlugosc - len(liczba))) + liczba def dodawanie(A, B, system): maxdl = max(len(A), len(B)) A = konwersja(A, maxdl) B = konwersja(B, maxdl) p = 0 wynik = "" for i in range(-1, -maxdl-1, -1): suma = maska.find(A[i]) + maska.find(B[i]) + p p = suma // system wynik += maska[suma % system] wynik = wynik[::-1] return wynik A = input("Podaj pierwsza liczbe:") B = input("Podaj druga liczbe:") sys = int(input("Podaj system liczbowy:")) print(dodawanie(A, B, sys)) def dodawanie(A, B, system): maxdl = max(len(A), len(B)) A = konwersja(A, maxdl) B = konwersja(B, maxdl) p = 0 wynik = "" for i in range(-1, -maxdl-1, -1): suma = maska.find(A[i]) + maska.find(B[i]) + p p = suma // system wynik += maska[suma % system] if p: wynik += maska[p] wynik = wynik[::-1] return wynik
buran write Feb-12-2021, 01:46 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.