In Python write a program that prompts the user for six elements and their atomic numbers and stores them in a list. Each element and weight pair should also be a list. After the values have been entered, print the list as it entered. Then print the first two characters from the element names (the first character capitalized and the second in lower case) along with the atomic number, starting with the element with the lowest atomic number. You must check that the user enters at least two characters for the element name.
Sample dialog:
Enter the element name: Neon
Enter the atomic number: 10
Enter the element name: argon
Enter the atomic number: 18
Enter the element name: lead
Enter the atomic number: 82
Enter the element name: Radon
Enter the atomic number: 86
Enter the element name: Zinc
Enter the atomic number: 30
Enter the element name: Aurum
Enter the atomic number: 79
[['Neon', 10], ['argon', 18], ['lead', 82], ['Radon', 86], ['Zinc', 30], ['Gold', 79]]
Ne 10
Code:
f=[]
for i in range(6):
x=input('enter an element
name:')
if
len(x)<2:
#checking the length of the element name
print('element must
contain 2 letters') #if length is less than
2
x=input('enter another
element name:') #we are asking
another input
y=int(input('enter its atomic number:'))
l=[x,y]
f.append(l)
print(f)
for i in f:
s=''
a=i[0][0].upper()
#capitalizing the first letter
b=i[0][1].lower()
#converting the 2nd letter to lowercase
s=s+a+b
i[0]=s
#changing the element's name into two letters
d=len(f)
for i in range(d):
for j in range(0,d-i-1):
if
f[j][1]>f[j+1][1]:
#sorting the list in the increasing order of atomic name
f[j][1],f[j+1][1]=f[j+1][1],f[j][1]
print('')
for i in f:
for j in i:
print(j,end='
')
#printing element & it's atomic number
print('\n')
Reference:
Output :
Note : I have provided you needed information.If you find any difficulty in understanding it or if you need any explanation please comment.If you are satisfied with my answer please upvote. Thank you.
Get Answers For Free
Most questions answered within 1 hours.