Changing units with tens - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Changing units with tens (/thread-38381.html) |
Changing units with tens - kazek17 - Oct-06-2022 Hi, i have to draw int number from (1000, 9999) and create new number where I have to change units with tens and hundreds with thousands from the first number, Im new in python so it has to be done in the simplest way. I have something like this: import random from typing import Final RANGE_MIN: Final[int] = 1000 RANGE_MAX: Final[int] = 9999 n = random.randint(RANGE_MIN, RANGE_MAX) print(f'{n = }') units = int((n // 10 ** 0) % 10) tens = (n // 10 ** 1) % 10 hundreds = (n // 10 ** 2) % 10 thousands = (n // 10 ** 3) % 10 print(f'{units = }\n{tens = }\n{hundreds = }\n{thousands = }')Now i dont know how to create the new number RE: Changing units with tens - rob101 - Oct-06-2022 From what I can see (but I may be wrong about this) I think the only issue you have, is with your print() function formatting.# line 6 print(f'n = {n}') # line 11 print(f'units = {units}\ntens = {tens}\nhundreds = {hundreds}\nthousands = {thousands}')
|