Getting error while running a below program in python
data = read_data()
batsman_name = first_batsman(data)
def first_batsman(data=data):
innings = data['innings'][0]
first_innings = innings['1st innings']
deliveries = first_innings['deliveries']
first_ball =(deliveries[0] [0.1])
first_batsman = first_ball['batsman']
return(first_batsman)
print(first_batsman)
getting error as :
return(first_batsman)
^
IndentationError: unexpected indent
I even tried below program :
data = read_data()
batsman_name = first_batsman(data)
def first_batsman(data=data):
innings = data['innings'][0]
first_innings = innings['1st innings']
deliveries = first_innings['deliveries']
first_ball =(deliveries[0] [0.1])
first_batsman = first_ball['batsman']
return(first_batsman)
print(first_batsman)
But still getting error as :
return(first_batsman)
SyntaxError: 'return' outside function
What is the solution for this?
I think you missunderstood intentations: may read this
To your code, you may want to try something like this:
class First_Batsman( object ) :
def __init__( self ):
self.innings = data['innings'][0]
self.first_innings = innings['1st innings']
self.deliveries = first_innings['deliveries']
self.first_ball = deliveries[0][0.1]
self.first_batsman = first_ball['batsman']
def __str__(self):
return str(self.innings,self.first_innings,self.deliveries,
self.first_ball,self.first_batsman)
data = read_data()
batsman_name = first_batsman( data )
print( first_batsman )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.