Plz help with this

Joined
Jun 17, 2024
Messages
4
Reaction score
0
Create a program that reads the number of protons, the number of electrons, and the number of neutrons of an atom and writes on the screen whether it is neutral, positively or negatively charged, and the number of masses.
 
Joined
Jul 4, 2023
Messages
406
Reaction score
47
I think the code should look something like this (as simplest version as possible, of course we can write more advanced code, but I don't know what level you are at with python)

[ working code on-line ]
Python:
def main():
    # Get input from the user
    protons   = int(input("Enter the number of protons: "))
    electrons = int(input("Enter the number of electrons: "))
    neutrons  = int(input("Enter the number of neutrons: "))

    # Calculate the atomic mass
    atomic_mass = protons + neutrons

    # Determine the charge of the atom
    if protons == electrons:
        charge_status = "neutral"
    elif protons > electrons:
        charge_status = "positively charged"
    else:
        charge_status = "negatively charged"

    # Display the results
    print(f"The atom is {charge_status}.")
    print(f"The atomic mass is {atomic_mass}.")

if __name__ == "__main__":
    main()
    input("\n\nPress Enter to Exit")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,818
Messages
2,569,727
Members
45,664
Latest member
Phil79581

Latest Threads

Top