Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
The following is giving me a syntax error at (def__init__(self, price, max_speed, total_miles_ridden, initial_miles = 0):)
I'm also wondering if I can concatenate like this: self.total_miles_ridden + 10?
^:
class Bike(object):
def__init__(self, price, max_speed, total_miles_ridden, initial_miles = 0):
self.price = price
self.max_speed = max_speed
self.total_miles_ridden = total_miles_ridden
self.initial_miles = initial_miles
def displayinfo(self):
print("The price is ", self.price)
print("This bike's max speed is ", self.max_speed)
print("The total miles is ", self.total_miles_ridden)
def ride(self):
print("Riding ", self.total_miles_ridden + 10) #add 10miles to total
def reverse(self):
print("Reversing " self.total_miles_ridden - 5) #minus 5 miles from total
bike1 = new Bike(200, '25mph')
print bike1
I think you're missing a space between def and init.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
Im trying to create a function which will convert temperatures based on the temperature that is being converted from to the temperature which we want. However the output of my code is none when I test it.
def convertTemperature(T, unitFrom, unitTo):
if unitFrom=="Fahrenheit" and unitTo=="Celsius":
T=(T-32)/1.8
return T
elif unitFrom=="Kelvin" and unitTo=="Celcius":
T=T-273.15
return T
elif unitFrom=="Celcius" and unitTo=="Fahrenheit":
T=1.8*T+32
return T
elif unitFrom=="Kelvin" and unitTo=="Fahrenheit":
T=1.8*T-459.67
return T
elif unitFrom=="Celcius" and unitTo=="Kelvin":
T=T+273.15
return T
elif unitFrom=="Fahrenheit" and unitTo=="Kelvin":
T=(T*459.67)/1.8
return T
the unitFrom parameter is the current temperature, T is the temperature and unitTo is the temperature to which I want to convert.
I tried testing it with print(convertTemperature(50.0, "Fahrenheit", "Celcius")) but the output was none.
It is just a spelling mistake Celsius not Celcius
This will work
def convertTemperature(T, unitFrom, unitTo):
if unitFrom=="Fahrenheit" and unitTo=="Celsius":
T=(T-32)/1.8
return T
elif unitFrom=="Kelvin" and unitTo=="Celsius":
T=T-273.15
return T
elif unitFrom=="Celsius" and unitTo=="Fahrenheit":
T=1.8*T+32
return T
elif unitFrom=="Kelvin" and unitTo=="Fahrenheit":
T=1.8*T-459.67
return T
elif unitFrom=="Celsius" and unitTo=="Kelvin":
T=T+273.15
return T
elif unitFrom=="Fahrenheit" and unitTo=="Kelvin":
T=(T*459.67)/1.8
return T
print(convertTemperature(50.0, "Fahrenheit", "Celsius"))
Hi you have use wrong word Celsius
It would be Celcius
Your program is right except spelling mistake
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I get an invalid syntax error at:
if sum(severe_symptoms_list) >= 2
I have set the values for the severe and moderate symptoms slots to True and False depending on what answer was given by the user to a YES/NO question. What have i done wrong ?
class ActionHowManySymptoms(Action):
def name(self) -> Text:
return "action_how_many_symptoms"
def run (self, dispatcher, tracker, domain):
severe_symptom1 = tracker.get_slot('severe_symptom_one')
severe_symptom2 = tracker.get_slot('severe_symptom_two')
severe_symptom3 = tracker.get_slot('severe_symptom_three')
severe_symptom4 = tracker.get_slot('severe_symptom_four')
moderate_symptom1 = tracker.get_slot('moderate_symptom_one')
moderate_symptom2 = tracker.get_slot('moderate_symptom_two')
moderate_symptom3 = tracker.get_slot('moderate_symptom_three')
moderate_symptom4 = tracker.get_slot('moderate_symptom_four')
severe_symptoms_list = [severe_symptom1, severe_symptom2, severe_symptom3, severe_symptom4]
moderate_symptoms_list = [moderate_symptom1, moderate_symptom2, moderate_symptom3, moderate_symptom4]
True = 1
if sum(severe_symptoms_list) >= 2
dispatcher.utter_response(response="utter_some_severe_symptoms", tracker)
elif sum(severe_symptoms_list) == 1
dispatcher.utter_response(response="utter_one_severe_symptoms", tracker)
else:
dispatcher.utter_response(response="utter_no_severe_symptoms", tracker)
if sum(moderate_symptoms_list) >= 2
dispatcher.utter_message(response="utter_some_moderate_symptoms")
elif sum(moderate_symptoms_list) == 1
dispatcher.utter_message(response="utter_one_moderate_symptoms")
else:
dispatcher.utter_message(response="utter_no_moderate_symptoms")
return[]
Try to code in a more decent presentable manner. It will help you in the long run
if (sum(severe_symptoms_list) >= 2):
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I need to print following info using unnecessary argument (track):
def make_album(singer, album, track = ''):
album = {'singer_name' : singer, 'slbum' : album}
if track:
album['track'] = track
return album
output = make_album('Linkin Park', 'October')
print(output)
output = make_album('Lara Fabian', 'Ju\'tem', 13)
print(output)
output = make_album('Space Girls', 'Viva')
print(output)
But the output is kind of
None
{'singer_name': 'Lara Fabian', 'slbum': "Ju'tem", 'track': 13}
None
How to denote args to avoid none output
you have a return in your function only if your track argument is not an empty string otherwise your function returns None to fix you can use:
def make_album(singer, album, track = ''):
album = {'singer_name' : singer, 'slbum' : album}
if track:
album['track'] = track
return album
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I'm having the below code which is really simple, but I just can't figure out why I'm getting the above error. I can't seem to call the function defined above, as it is a boolean object??
def server(jobs):
# master clock jumps to next job
global master
master = jobs[0][0]
jobs = [(1, 2.1),(2, 3.3),(3, 1.1),(5, 0.5),(15, 1.7)]
# master clock
master = 0
# server = true when busy, server = false when idle
server = False
next_arrival = jobs[0][0]
# assuming no future arrivals
next_departure = np.inf
job_list = []
print("master clock: " + str(master) + ", next arrival time: " + str(next_arrival) + ", next departure time: " + str(next_departure) + ", job list: " + str(job_list))
server(jobs)
You shadowed your function name with a bool variable when you wrote server = false. You can't have a function and a variable with the same name in the same scope.
Name that variable or the function something else, because False() doesn't make any sense.
You just need to change the name of the function. Change the function name from server to server_new and it will work.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I am having issues with a defined name error message in Python. I know there are quite a few responses to this question, but I cannot seem to find one that fits my situation. My code is as follows:
#Gets the input of the property value from the user and calculates the individual and total revenue
def main():
class_A_input = int(input('Please enter the number of Class A seats sold: '))
class_B_input = int(input('Please enter the number of Class B seats sold: '))
class_C_input = int(input('Please enter the number of Class C seats sold: '))
#Declares the cost for each class of ticket
class_A_cost = 20
class_B_cost = 15
class_C_cost = 10
#Passes the variable for each ticket class
class_A(class_A_input, class_A_cost)
class_B(class_B_input, class_B_cost)
class_C(class_C_input, class_C_cost)
#Calculates the total revenue
total_revenue = (class_A_input * class_A_cost) + ,\
(class_B_input * class_B_cost) + (class_C_input * class_C_cost)
print ('Total tickets revenue is $',format(total_revenue,',d'),sep='')
#Calculates the class A revenue
def class_A(A_input, A_cost):
class_A_revenue = A_input * A_cost
print ('The amount of Class A revenue is $',format(class_A_revenue,',d'),sep='')
#Repeat definitions for Class B and Class C
main()
I am running Python 3.6.0 and I am getting the following name error:
total_revenue = (class_A_input * class_A_cost) + ,\
(class_B_input * class_B_cost) + (class_C_input * class_C_cost)
NameError: name 'class_A_input' is not defined
I don't think I am declaring the variable before I use it. I have tried a variety of different solutions with no success. So what am I doing wrong?
This looks like an indentation issue. total_revenue is global and trying to use local variable from main() in its calculation.
p.s. You should learn about functions in order to help you reduce duplication in your code.