Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
clean script by code
#1
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
Reply
#2
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 literal
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)"]
}
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply
#3
Also, please fix indentatation.
Reply
#4
In both ways gives it me syntax error
Reply
#5
your indentation is incorrect. That alone will give you error.
Reply
#6
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"
Reply
#7
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'])
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#8
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.
Reply
#9
(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
Output:
In [77]: 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)"]) In [78]: champions['verstappen'] Out[78]: [38, '30/07/1997', 'Belgio', 'Australia 2015', 60, 3, 0, 0]
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Can i clean this code ? BSDevo 8 850 Oct-28-2023, 05:50 PM
Last Post: BSDevo
  Clean Up Script rotw121 2 981 May-25-2022, 03:24 PM
Last Post: rotw121
  How to clean UART string Joni_Engr 4 2,414 Dec-03-2021, 05:58 PM
Last Post: deanhystad
  How to clean session mqtt SayHiii 0 1,970 Dec-09-2019, 07:56 AM
Last Post: SayHiii
  how to clean up unstarted processes? Skaperen 2 2,203 Aug-27-2019, 05:37 AM
Last Post: Skaperen
  Code Clean-up and Maya/Python Slicing issues mvvthology 1 2,393 Aug-05-2019, 10:43 PM
Last Post: Yoriz
  sched.scheduler -> clean denisit 1 2,818 Nov-28-2018, 09:52 AM
Last Post: Gribouillis
  clean up list elements and replace metalray 7 4,167 Aug-30-2018, 08:13 AM
Last Post: metalray
  Clean Data using NLTK disruptfwd8 0 3,303 May-12-2018, 11:21 PM
Last Post: disruptfwd8
  Clean up Code liamwemyss 1 3,337 Jun-07-2017, 08:36 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020