This is the original code that works:
def printed_models(unprinted_designs,completed_models): while unprinted_designs: current_design= unprinted_designs.pop() print(f"Printing model: {current_design}") completed_models.append(current_design) def show_completed_models(completed_models): print("nThe following models have been printed:") for completed_model in completed_models: print(completed_model) unprinted_designs=['robot','rocket','terminator'] completed_models=[] printed_models(unprinted_designs,completed_models) show_completed_models(completed_models)
This is the code after adding [:] for unprinted_designs to keep the original list as the book shows. It gave me an syntax error after I added [:]
def print_models(unprinted_designs[:], completed_models): while unprinted_designs: current_design= unprinted_designs.pop() print(f"Printing model: {current_design}") completed_models.append(current_design) def show_completed_models(completed_models): print("nThe following models have been printed:") for completed_model in completed_models: print(completed_model) unprinted_designs=['robot','rocket','terminator'] completed_models=[] printed_models(unprinted_designs,completed_models) show_completed_models(completed_models)
submitted by /u/homelander159
[link] [comments]
r/learnpython This is the original code that works: def printed_models(unprinted_designs,completed_models): while unprinted_designs: current_design= unprinted_designs.pop() print(f”Printing model: {current_design}”) completed_models.append(current_design) def show_completed_models(completed_models): print(“nThe following models have been printed:”) for completed_model in completed_models: print(completed_model) unprinted_designs=[‘robot’,’rocket’,’terminator’] completed_models=[] printed_models(unprinted_designs,completed_models) show_completed_models(completed_models) This is the code after adding [:] for unprinted_designs to keep the original list as the book shows. It gave me an syntax error after I added [:] def print_models(unprinted_designs[:], completed_models): while unprinted_designs: current_design= unprinted_designs.pop() print(f”Printing model: {current_design}”) completed_models.append(current_design) def show_completed_models(completed_models): print(“nThe following models have been printed:”) for completed_model in completed_models: print(completed_model) unprinted_designs=[‘robot’,’rocket’,’terminator’] completed_models=[] printed_models(unprinted_designs,completed_models) show_completed_models(completed_models) submitted by /u/homelander159 [link] [comments]
This is the original code that works:
def printed_models(unprinted_designs,completed_models): while unprinted_designs: current_design= unprinted_designs.pop() print(f"Printing model: {current_design}") completed_models.append(current_design) def show_completed_models(completed_models): print("nThe following models have been printed:") for completed_model in completed_models: print(completed_model) unprinted_designs=['robot','rocket','terminator'] completed_models=[] printed_models(unprinted_designs,completed_models) show_completed_models(completed_models)
This is the code after adding [:] for unprinted_designs to keep the original list as the book shows. It gave me an syntax error after I added [:]
def print_models(unprinted_designs[:], completed_models): while unprinted_designs: current_design= unprinted_designs.pop() print(f"Printing model: {current_design}") completed_models.append(current_design) def show_completed_models(completed_models): print("nThe following models have been printed:") for completed_model in completed_models: print(completed_model) unprinted_designs=['robot','rocket','terminator'] completed_models=[] printed_models(unprinted_designs,completed_models) show_completed_models(completed_models)
submitted by /u/homelander159
[link] [comments]