Учитывая приведенный ниже код - 2 словаря и для циклов.
Если я отменю отступ строки sim_choice = raw_input("\nPlease enter item code for the SIM card you want?: ")
, оператор print над ней print(" " + str(value))
печатает все значения в словаре sims, но затем остальные заявление становится недействительным. В настоящее время вывод только печать первого значения в симках? пример:
Please tell me your name? X
Hello X
Please enter item code for the phone or tablet you want?: BPCM
Item Code Chosen BPCM['Phone', 'Description: Compact', 'price', 29.99]
As you chose a phone, would you like a SIM free or Pay As You Go for - ['Phone', 'Description: Compact', 'price', 29.99]
Item Code: SMNO
['SIM card', 'Description: SIM Free (no SIM card purchased)', 'price', 0.0]
Please enter item code for the SIM card you want?:
Не могу понять, почему он не печатает все значения из словаря sims в своем текущем состоянии?
device = {
'BPCM' : ['Phone', 'Description: Compact', 'price', 29.99],
'BPSH' : ['Phone', 'Description: Clam Shell', 'price', 49.99],
'RTMS' : ['Tablet', 'Description: RoboTab - 10-inch screen and 64GB memory', 'price', 299.99],
'RTLM' : ['Tablet', 'Description: RoboTab - 10-inch screen and 256 GB memory', 'price', 499.99],
}
sims = {
"SMNO" : ['SIM card', 'Description: SIM Free (no SIM card purchased)', 'price', 0.00],
"SMPG" : ['SIM card', 'Description: Pay As You Go (SIM card purchased)', 'price', 9.99],
}
print("Hello customer, here is your list of phones or tablets. Please choose a phone or tablet by entering your name and the item code:")
for key, value in device.items():
print("\nItem Code: " + key)
print(" " + str(value))
name = raw_input("\nPlease tell me your name? ")
print("Hello " + name)
device_choice = raw_input("Please enter item code for the phone or tablet you want?: ")
if device_choice in device.keys():
print("Item Code Chosen " + device_choice + str(device[device_choice]))
sim_cards = ['BPCM', 'BPSH']
if device_choice in sim_cards:
print("\nAs you chose a phone, would you like a SIM free or Pay As You Go for - " + str(device[device_choice]))
for key, value in sims.items():
print("\nItem Code: " + key)
print(" " + str(value))
sim_choice = raw_input("\nPlease enter item code for the SIM card you want?: ")
else:
print("Item Code Chosen " + device_choice + str(device[device_choice]))