![]() |
clean script by code - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: clean script by code (/thread-13401.html) |
clean script by code - fen1c5 - Oct-13-2018 SO guys. I made this program(I think nice... :D): bottas=[77,"28/08/1989","Finlandia","Australia 2013",98,3,4,0] hamilton=[44,"07/01/1985","Inghilterra","Australia 2007",208,62,74,"4(2008-2014-2015-2017)"] raikkonen=[7,"17/10/1979","Finlandia","Australia 2001",273,20,17,"1(2007)"] vettel=[5,"03/07/1987","Germania","Stati Uniti 2007",198,47,50,"4(2010-2011-2012-2013)"] verstappen=[38,"30/07/1997","Belgio","Australia 2015",60,3,0,0] ricciardo=[3,"01/07/1989","Australia","Gran Bretagna 2011",129,5,1,0] alonso=[14,"29/07/1981","Spagna","Australia 2001",293,32,22,"2(2005-2006)"] def pilota(dato): indice=0 print(" "*25,"*"*50) while indice<8: etichetta=["Numero di gara:","Data di nascita:","nazione:","Esordio:","Presenze:","Vittorie:","Pole position:","Titoli iridati:"] print(" "*30,"*",etichetta[indice],dato[indice]) indice+=1 print(" "*25,"*"*50) print("PILOTI FORMULA 1 2018") print("Schede dei piloti del campionato mondiale di Formula 1\n") name="null" while name=="null": name=input("Nome del pilota del quale vuoi le statistiche: ") name=name.lower() if name=="bottas": pilota(bottas) name="null" elif name=="hamilton": pilota(hamilton) name="null" elif name=="raikkonen": pilota(raikkonen) name="null" elif name=="vettel": pilota(vettel) name="null" elif name=="verstappen": pilota(verstappen) name="null" elif name=="ricciardo": pilota(ricciardo) name="null" elif name=="alonso": pilota(alonso) name="null" elif name=="quit": print("E' stato un piacere. A presto!") print("++++++++++++++++++++FINISH++++++++++++++++++++")now, I woant clean every time I enter piolta's name. A more professional way to scroll the lines. Thank you advance RE: clean script by code - volcano63 - Oct-13-2018 That's the reason BDFL created dict champions = dict( bottas=[77,"28/08/1989","Finlandia","Australia 2013",98,3,4,0] hamilton=[44,"07/01/1985","Inghilterra","Australia 2007",208,62,74,"4(2008-2014-2015-2017)"] raikkonen=[7,"17/10/1979","Finlandia","Australia 2001",273,20,17,"1(2007)"] vettel=[5,"03/07/1987","Germania","Stati Uniti 2007",198,47,50,"4(2010-2011-2012-2013)"] verstappen=[38,"30/07/1997","Belgio","Australia 2015",60,3,0,0] ricciardo=[3,"01/07/1989","Australia","Gran Bretagna 2011",129,5,1,0] alonso=[14,"29/07/1981","Spagna","Australia 2001",293,32,22,"2(2005-2006)"])or - by dict literalchampions = { "bottas": [77,"28/08/1989","Finlandia","Australia 2013",98,3,4,0], "hamilton": [44,"07/01/1985","Inghilterra","Australia 2007",208,62,74,"4(2008-2014-2015-2017)"] } RE: clean script by code - Larz60+ - Oct-13-2018 Also, please fix indentatation. RE: clean script by code - fen1c5 - Oct-15-2018 In both ways gives it me syntax error RE: clean script by code - Larz60+ - Oct-15-2018 your indentation is incorrect. That alone will give you error. RE: clean script by code - fen1c5 - Oct-15-2018 My indentation is correct: champions = dict( #Dati dei piloti bottas=[77,"28/08/1989","Finlandia","Australia 2013",98,3,4,0] hamilton=[44,"07/01/1985","Inghilterra","Australia 2007",208,62,74,"4(2008-2014-2015-2017)"] raikkonen=[7,"17/10/1979","Finlandia","Australia 2001",273,20,17,"1(2007)"] vettel=[5,"03/07/1987","Germania","Stati Uniti 2007",198,47,50,"4(2010-2011-2012-2013)"] verstappen=[38,"38,""30/07/1997","Belgio","Australia 2015",60,3,0,0] ricciardo=[3,"01/07/1989","Australia","Gran Bretagna 2011",129,5,1,0] alonso=[14,"29/07/1981","Spagna","Australia 2001",293,32,22,"2(2005-2006)"]) def pilota(dato): etichetta=["Numero di gara:","Data di nascita:","nazione:","Esordio:","Presenze:","Vittorie:","Pole position:","Titoli iridati:"] print(" "*20,"*"*50) indice=0 while indice<8: print(" "*25,"*",etichetta[indice],dato[indice]) indice+=1 print(" "*20,"*"*50) print("\n"*10) name="null" while name=="null": print("PILOTI FORMULA 1 2018") print("Schede dei piloti del campionato mondiale di Formula 1") print(" ") name=input("Pilota del qule vuoi le informazioni: ") name=name.lower() if name=="bottas": pilota(bottas) name="null" elif name=="hamilton": pilota(hamilton) name="null" elif name=="raokkonen": pilota(raikkonen) name="null" elif name=="vettel": pilota(vettel) name="null" elif name=="verstappen": pilota(verstappen) name="null" elif name=="ricciardo": pilota(ricciardo) name="null" elif name=="alonso": pilota(alonso) name="null" elif name=="quit": print(" "*20,"*"*50) print(" "*30,"E' staot un piacere. A presto!") print(" "*22,"====================FINISH====================") print(" "*20,"*"*50) print("\n"*10) else: name="null" RE: clean script by code - ichabod801 - Oct-15-2018 To be fair, Volcano, your code does have bugs as well. Here are corrected versions of Volcano's dictionary code: champions = { 'bottas': [77,"28/08/1989","Finlandia","Australia 2013",98,3,4,0], 'hamilton': [44,"07/01/1985","Inghilterra","Australia 2007",208,62,74,"4(2008-2014-2015-2017)"], 'raikkonen': [7,"17/10/1979","Finlandia","Australia 2001",273,20,17,"1(2007)"], 'vettel': [5,"03/07/1987","Germania","Stati Uniti 2007",198,47,50,"4(2010-2011-2012-2013)"], 'verstappen': [38,"30/07/1997","Belgio","Australia 2015",60,3,0,0], 'ricciardo': [3,"01/07/1989","Australia","Gran Bretagna 2011",129,5,1,0], 'alonso': [14,"29/07/1981","Spagna","Australia 2001",293,32,22,"2(2005-2006)"]} print(champions['hamilton']) champions2 = dict( [['bottas', [77,"28/08/1989","Finlandia","Australia 2013",98,3,4,0]], ['hamilton', [44,"07/01/1985","Inghilterra","Australia 2007",208,62,74,"4(2008-2014-2015-2017)"]], ['raikkonen', [7,"17/10/1979","Finlandia","Australia 2001",273,20,17,"1(2007)"]], ['vettel', [5,"03/07/1987","Germania","Stati Uniti 2007",198,47,50,"4(2010-2011-2012-2013)"]], ['verstappen', [38,"30/07/1997","Belgio","Australia 2015",60,3,0,0]], ['ricciardo', [3,"01/07/1989","Australia","Gran Bretagna 2011",129,5,1,0]], ['alonso', [14,"29/07/1981","Spagna","Australia 2001",293,32,22,"2(2005-2006)"]]]) print(champions2['hamilton']) RE: clean script by code - fen1c5 - Oct-15-2018 I think you not understood what I want. I want every time I insert the name of a pilote, the screen is cleaned from the previos view. RE: clean script by code - volcano63 - Oct-16-2018 (Oct-15-2018, 01:28 PM)ichabod801 Wrote: To be fair, Volcano, your code does have bugs as well. Here are corrected versions of Volcano's dictionary code: I was trying to show an example, I did not check for errors. My effort was wasted anyway, since OP missed the fact that drivers' info should be obtained by key driver = champions.get(name) PS I have forgotten to add commas, otherwise it was OK
|