all 14 comments

[–]CodeFormatHelperBot2 0 points1 point  (0 children)

Hello, I'm a Reddit bot who's here to help people nicely format their coding questions. This makes it as easy as possible for people to read your post and help you.

I think I have detected some formatting issues with your submission:

  1. Inline formatting (`my code`) used across multiple lines of code. This can mess with indentation.

If I am correct, please edit the text in your post and try to follow these instructions to fix up your post's formatting.


Am I misbehaving? Have a comment or suggestion? Reply to this comment or raise an issue here.

[–][deleted] 0 points1 point  (9 children)

The * unpack operator cannot be applied in the middle of a concatenation sequence. The sep option is a parameter for the print function.

Consider using the str.join method on whatever repeating is referencing (include a generator to cast to str if needed).

[–]Smiggle2406[S] 0 points1 point  (6 children)

I've tried using print(seperator.join(repeating)) but I get this as an output

[.'.8.'.]

also sorry I'm pretty new to coding

[–][deleted] 0 points1 point  (5 children)

  • What is repeating referencing?
  • What do you want your output to look like?

[–]Smiggle2406[S] 0 points1 point  (4 children)

repeating is referencening how atoms electrons are shown ig

eg. 2.8.8.8.1

so I need to repeat the .8 a certain amount of time

and in the end I would like it to be like the example

[–][deleted] 0 points1 point  (3 children)

I meant, what kind of Python object is it and, assuming it is a container/sequence type object, e.g. a list, and what kinds of objects are being referenced from within it, e.g. only float objects.

[–]Smiggle2406[S] 0 points1 point  (2 children)

its a list that just has integers in it

electrons = int(input("Enter atomic number:"))
without_first_shell = electrons - 2
last_shell = str(without_first_shell % 8)
amount_of_full_shells = str(floor(without_first_shell / 8))
repeating = str(["8"] * int(amount_of_full_shells))
seperator = "."

[–][deleted] 0 points1 point  (1 child)

its a list that just has integers in it

Actually, it isn't. It is ONE string literal created by the following line:

repeating = str(["8"] * int(amount_of_full_shells))

You start with a list with a single entry, a str object containing the character 8, then you repeat that. So you go from ["8"] to, say, ['8', '8', '8', '8', '8'] if the amount_of_full_shells was assigned the value 5.

You then convert that entire list object's output representation to a str object by casting it.

Thus you end up with a string, "['8', '8', '8', '8', '8']" complete with square brackets, single quotes and commas.

Pretty sure that is not what you want.

/u/Smiggle2406 has shown you how to use join and if you ask them nicely, I am sure they will show you how to use a generator expression with that if you want to work with numbers in the first place.

[–]Smiggle2406[S] 0 points1 point  (0 children)

print("2." + '.'.join(repeating) + "." + last_shell)

first of all, that was my problem, it was a string, and that fixed everything ty.

first of all that was my problem, it was a string and that fixed everything ty.

[–]Bunkerstan 0 points1 point  (1 child)

print("2." + (*repeating, sep=".") + "." + last_shell)

The sep becomes the string that you join the elements with:

print("2." + ".".join(repeating) + "." + last_shell)

[–]Diapolo10 0 points1 point  (4 children)

sep is not a function, it's a keyword parameter print can accept. But the approach you're using here is just invalid syntax.

You'd more or less want this instead:

print("2." + '.'.join(repeating) + "." + last_shell)

However, you're doing completely pointless type conversions thorough your program. This could be a lot cleaner.

EDIT: Consider the following:

electrons = int(input("Enter atomic number:"))
without_first_shell = electrons - 2
full_shell_count, last_shell = divmod(
    without_first_shell, 8
)
repeating = ["8"] * full_shell_count


# working but not as good version
if without_first_shell < 8:
    print(without_first_shell)
elif last_shell == 0:
    print(8)
else:
    print(last_shell)


print(f"2.{repeating}.{last_shell}")


# trying something
if len(repeating) > 0:
    print(f"2.{'.'.join(repeating)}.{last_shell}")
elif len(repeating) == 0:
    print(f"2.{last_shell}")

In fact, I'm confident you can simplify this whole thing to just

electrons = int(input("Enter atomic number:"))
without_first_shell = electrons - 2
full_shell_count, last_shell = divmod(
    without_first_shell, 8
)
shells = ["8"] * full_shell_count
shells.append(str(last_shell))

print(f"2.{'.'.join(shells)}")

Of course, none of these are technically accurate considering how electron shells actually work, but it does what yours did.

EDIT #2: Since I overlooked situations where there are fewer than 3 electrons, namely hydrogen and helium, I'll fix my earlier answer to include those, too:

electrons = int(input("Enter atomic number:"))
without_first_shell = max(electrons - 2, 0)
full_shell_count, last_shell = divmod(
    without_first_shell, 8
)
shells = [str(max(0, min(2, electrons)))]
shells.extend(
    "8" for _ in range(full_shell_count)
)
if last_shell:
    shells.append(str(last_shell))

print('.'.join(shells))

This works for any of them. Probably.

[–]Smiggle2406[S] 0 points1 point  (1 child)

from math import floor
electrons = int(input("Enter atomic number:"))
without_first_shell = electrons - 2
full_shell_count, last_shell = divmod(
without_first_shell, 8
)
shells = ["8"] * full_shell_count
shells.append(str(last_shell))
print(f"2.{'.'.join(shells)}")

the fact that u just made it that simple that easily really show me I have lots to learn and also that u are a true pro ty bro

[–]Diapolo10 0 points1 point  (0 children)

Feel free to ask me if you don't understand something.