0

I am working on a project and this is a sample doubt from my project

a = int(input("Enter Atomic Number: ")
e1 = "Hydrogen"
e2 = "Helium"
e3 = "Lithium"

Now, the program must print "Hydrogen" if a = 1 and it must print "Helium" if a = 2 Note that I must do it for whole 118 elements and cannot use if statements.

Harsha Biyani
  • 7,049
  • 9
  • 37
  • 61

2 Answers2

3

You need to use some mapping type like dict. I Have made some changes to show you example hot it can be solved.

a = int(input("Enter Atomic Number: "))
elements = {
    1: "Hydrogen",
    2: "Helium",
    3: "Lithium"
}
element = elements.get(a, "Element not found")
print(element)
deceze
  • 510,633
  • 85
  • 743
  • 889
Take_Care_
  • 1,957
  • 1
  • 22
  • 24
1

Use dictionary data structure

a = int(input("Enter Atomic Number: ")
elements={ 1: "Hydrogen" ,2: "Helium" }
print(elements[a])
Jaya Shankar B
  • 121
  • 2
  • 8