Python Forum
Changing units with tens
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Changing units with tens
#1
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
Larz60+ write Oct-06-2022, 09:50 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use BBCode tags on future posts.
Reply
#2
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}')
Output:
#test input n = 1425 #output n = 1425 units = 5 tens = 2 hundreds = 4 thousands = 1
Sig:
>>> import this

The UNIX philosophy: "Do one thing, and do it well."

"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse

"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to find adjacent units in a line in the hexagon of the array xiaoshu1208 2 2,071 Mar-12-2019, 10:19 PM
Last Post: xiaoshu1208

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020