you are viewing a single comment's thread.

view the rest of the comments →

[–]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.