Your second code is not working because you have not quoted a,s,m,d
in condition making because of that it is acting like a variable.see here↓
if choice == a : print ('well done')
Here a is acting like a variable and you have put the value of variable a
as empty string sting so it doesn't match with the input value and thus return 'Invalid selection'
as output.
It should be ↓
if choice == 'a' : print ('well done')
See here how you should write that code.
# a = str() #There is no use to define these as a empty string
# s = str()
# m = str()
# d = str()
# choice = str()
choice = input('''Please select your sums, using:
a for addition
s for subtraction
m for multiplication
d for division
''')
if choice == 'a' : print ('well done')
elif choice == 's' : print('that's 2')#execfile (subtract)
elif choice == 'm' : print('that's 3')#execfile (subtract)
elif choice == 'd' : print('that's 4')#execfile (divide)
else: print('Invalid selection')
OR if you want to keep a,s,m,d
as a variable than↓
a = 'a'
s = 's'
m = 'm'
d = 'd'
#choice = str()
choice = input('''Please select your sums, using:
a for addition
s for subtraction
m for multiplication
d for division
''')
if choice == a : print ('well done')
elif choice == s : print('that's 2')#execfile (subtract)
elif choice == m : print('that's 3')#execfile (subtract)
elif choice == d : print('that's 4')#execfile (divide)
else: print('Invalid selection')
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…