Jan-13-2021, 07:43 PM
In this excerpt of something I'm playing with, I create a variable from the user input. The user inpout is then added to a string. The resultant string is then used to refer to a list.
But, when I try to print the contents of the list, the output is just the list's name, not the contents of the list itself. The script is:
The output looks like this:
Devices available:
0: 0.1K1A
1: 0.3K1A
2: 1K2A
3: 1K7A
4: 2K3A
5: 2.2K3A
6: 3K3A
7: 5K3A
8: 10K3A
9: 10K4A
10: 30K5A
11: 30K6A
12: 50K6A
13: 100K6A
14: 1M9A
Select the device to be measured = 0 to 14: 14
Selected thermistor is 1M9A
device14
[0.0007402387000000001, 0.0001760865, 6.865999000000001e-08]
You can see that when I input "14", the output correctly tells me the selected device is 1M9A, but then instead of printing the contents of list device14, it just prints "device14", its name.
The last line is just to show what should be printed.
I have tried:
but the output is the same.
I also tried:
the output was:
['d', 'e', 'v', 'i', 'c', 'e', '1', '4']
So, what is the difference between the value for selected_device and the same value (in this case device14) and the actual list name?
But, when I try to print the contents of the list, the output is just the list's name, not the contents of the list itself. The script is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
thermistor_list = [ "0.1K1A" , "0.3K1A" , "1K2A" , "1K7A" , "2K3A" , "2.2K3A" , "3K3A" , "5K3A" , "10K3A" , "10K4A" , "30K5A" , "30K6A" , "50K6A" , "100K6A" , "1M9A" ] device_list = [ "device0" , "device1" , "device2" , "device3 " , "device4" , "device5" , "device6" , "device7" , "device8" , "device9" , "device10" , "device11 " , "device12" , "device13" , "device14" ] device0 = [ 1.942952 * 10 * * - 3 , 2.989769 * 10 * * - 4 , 3.504383 * 10 * * - 7 ] # 0.1K1A device1 = [ 1.627660 * 10 * * - 3 , 2.933316 * 10 * * - 4 , 2.870016 * 10 * * - 7 ] # 0.3K1A device2 = [ 1.373168 * 10 * * - 3 , 2.772261 * 10 * * - 4 , 1.997412 * 10 * * - 7 ] # 1K2A device3 = [ 1.446059 * 10 * * - 3 , 2.683626 * 10 * * - 4 , 1.643561 * 10 * * - 7 ] # 1K7A device4 = [ 1.498872 * 10 * * - 3 , 2.379047 * 10 * * - 4 , 1.066953 * 10 * * - 7 ] # 2K3A device5 = [ 1.471388 * 10 * * - 3 , 2.376138 * 10 * * - 4 , 1.051058 * 10 * * - 7 ] # 2.2K3A device6 = [ 1.405027 * 10 * * - 3 , 2.369386 * 10 * * - 4 , 1.012660 * 10 * * - 7 ] # 3K3A device7 = [ 1.287450 * 10 * * - 3 , 2.357394 * 10 * * - 4 , 9.505200 * 10 * * - 8 ] # 5K3A device8 = [ 1.129241 * 10 * * - 3 , 2.341077 * 10 * * - 4 , 8.775468 * 10 * * - 8 ] # 10K3A device9 = [ 1.028444 * 10 * * - 3 , 2.392435 * 10 * * - 4 , 1.562216 * 10 * * - 7 ] # 10K4A device10 = [ 9.331754 * 10 * * - 4 , 2.213978 * 10 * * - 4 , 1.263817 * 10 * * - 7 ] # 30K5A device11 = [ 1.068981 * 10 * * - 3 , 2.120700 * 10 * * - 4 , 9.019537 * 10 * * - 8 ] # 30K6A device12 = [ 9.657154 * 10 * * - 4 , 2.106840 * 10 * * - 4 , 8.585481 * 10 * * - 8 ] # 50K6A device13 = [ 8.271111 * 10 * * - 4 , 2.088020 * 10 * * - 4 , 8.059200 * 10 * * - 8 ] # 100K6A device14 = [ 7.402387 * 10 * * - 4 , 1.760865 * 10 * * - 4 , 6.865999 * 10 * * - 8 ] # 1M9A # NOTE: 2.2K3A is OK-ish - Gives 25.53 °C @ 2200 Ω # SELECT THERMISTOR TYPE TO BE MEASURED AND EXTRACT CONSTANTS print ( "Devices available:" ) for index, value in enumerate (thermistor_list): print (index, value, sep = ": " ) device_number = int ( input ( "Select the device to be measured = 0 to 14: " )) x = int (device_number) selected_thermistor = (thermistor_list[x]) selected_device = (device_list[x]) print ( "Selected thermistor is" , selected_thermistor) print (selected_device) # Prints contents of user selected list print (device14) # Prints content of list by naming it directly |
Devices available:
0: 0.1K1A
1: 0.3K1A
2: 1K2A
3: 1K7A
4: 2K3A
5: 2.2K3A
6: 3K3A
7: 5K3A
8: 10K3A
9: 10K4A
10: 30K5A
11: 30K6A
12: 50K6A
13: 100K6A
14: 1M9A
Select the device to be measured = 0 to 14: 14
Selected thermistor is 1M9A
device14
[0.0007402387000000001, 0.0001760865, 6.865999000000001e-08]
You can see that when I input "14", the output correctly tells me the selected device is 1M9A, but then instead of printing the contents of list device14, it just prints "device14", its name.
The last line is just to show what should be printed.
I have tried:
1 |
selected_device = str (device_list[x]) |
I also tried:
1 |
selected_device = list (device_list[x]) |
['d', 'e', 'v', 'i', 'c', 'e', '1', '4']
So, what is the difference between the value for selected_device and the same value (in this case device14) and the actual list name?