FoodJoints = ('Mango Bar', 'Cool dude IceCream', 'Ripper Smoothies')
print ("Duude! Where do you wanna go dude?")
print ("Select a choice from 0-2 dude.")
Choice = input("Where you wanna go dude? ")
if Choice < 3:
print FoodJoints[Choice]
else:
Hey! This is a small, and quite embarrasing question but I need the ELSE here to lead back to the second line. What kind of loop do I want to use here? should I make it like this?
FoodJoints = ('Mango Bar', 'Cool dude IceCream', 'Ripper Smoothies')
def Checkpoint()
print ("Duude! Where do you wanna go dude?")
print ("Select a choice from 0-2 dude.")
Choice = input("Where you wanna go dude? ")
if Choice < 3:
print FoodJoints[Choice]
else:
Checkpoint()
FoodJoints = ('Mango Bar', 'Cool dude Ice Cream', 'Ripper Smoothies')
print ("Duude! Where do you wanna go dude?")
print ("Select a choice from 0-2 dude.")
Valid = 1
while Valid == 1:
Choice = input("Where you wanna go dude? ")
if Choice < 3:
print FoodJoints[Choice] + ("? Sweet dude! See you there dude.")
Valid = 0
else:
print ("DUUUUDE! Invalid choice dude!")
#Begin Menu
while MenuOpen == 1:
Choice = Menu(["Display value of VAR1", "Display value of VAR2", \
"Change value of VAR1", "Change value of VAR2", "Quit"], \
("What would you like to do? "))
if Choice + 1 == 1:
if VAR1DEF == 1:
VAR1.displayValue()
print VAR1
else:
print "VAR1 is not defined."
if Choice + 1 == 2:
if VAR2DEF == 1:
VAR2.displayValue()
else:
print "VAR2 is not defined."
if Choice + 1 == 3:
chVAR1 = input("What would you like to change VAR1 to? ")
VAR1.changeValue(chVAR1)
VAR1DEF = 1
When I define VAR1 and then tell the program to display the value, it comes up with:
<__main__.Test instance at 0x0250FA80>
To me it looks like VAR1 does not end up being defined. Halp?
I don't know Python, but that seems kinda counter intuitive, having a function called "displayValue" that doesn't display?
That has nothing to do with Python and everything to do with how he wrote the displayValue method:
class Test:
def displayValue(self):
return self.value
def changeValue(self, value):
self.value = value
Thanks for the help, can you elaborate on what return does?
It does the same thing it does in virtually every language it shows up in, it returns a value from a function. I can't explain it in simpler terms.
Also, what is __init__?
And the tutorial doesn't explain it? That must be a pretty poor tutorial. __init__ is a special built-in method for classes that is called whenever a new instance of a class is created and it's responsible for initializing that instance.
Rollback Post to RevisionRollBack
Never attribute to malice what can adequately be explained by incompetence.
So __init__ let's me Initialize a class? I can use classes fine, even without __init__
No, it lets you initialize an instance of a class. The initialization of a class *itself* occurs at the class definition (well, metaclasses let you do some weird things, but don't worry about those).
For example, a simple use of __init__ is as follows:
class Point:
def __init__(self, x, y):
self.x, self.y = x, y
origin = Point(0, 0)
This is a sparse example (a point class would usually come with a lot more functionality for whatever you wanted it for). The __init__ method gets called as part of the initialization sequence when you call Point. Point is the class, Point(0, 0) is an instance of the Point class. The __init__ method also allows arguments to be passed into a new instance. Certainly you could never use the __init__ method. You could also not use classes at all and still write anything, but you're just making things more difficult for yourself if you take this route.
Rollback Post to RevisionRollBack
Never attribute to malice what can adequately be explained by incompetence.
print ("Duude! Where do you wanna go dude?")
print ("Select a choice from 0-2 dude.")
Choice = input("Where you wanna go dude? ")
if Choice < 3:
print FoodJoints[Choice]
else:
Hey! This is a small, and quite embarrasing question but I need the ELSE here to lead back to the second line. What kind of loop do I want to use here? should I make it like this?
FoodJoints = ('Mango Bar', 'Cool dude IceCream', 'Ripper Smoothies')
def Checkpoint()
print ("Duude! Where do you wanna go dude?")
print ("Select a choice from 0-2 dude.")
Choice = input("Where you wanna go dude? ")
if Choice < 3:
print FoodJoints[Choice]
else:
Checkpoint()
Thanks guys.
FoodJoints = ('Mango Bar', 'Cool dude Ice Cream', 'Ripper Smoothies')
print ("Duude! Where do you wanna go dude?")
print ("Select a choice from 0-2 dude.")
Valid = 1
while Valid == 1:
Choice = input("Where you wanna go dude? ")
if Choice < 3:
print FoodJoints[Choice] + ("? Sweet dude! See you there dude.")
Valid = 0
else:
print ("DUUUUDE! Invalid choice dude!")
#Menu func
def Menu(list, ask):
for entry in list:
print 1 + list.index(entry),
print ") " + entry
return input(ask) -1
#Test Class
class Test:
def displayValue(self):
return self.value
def changeValue(self, value):
self.value = value
#Defining variables
VAR1 = Test()
VAR2 = Test()
VAR1DEF = 0
VAR2DEF = 0
MenuOpen = 1
#Begin Menu
while MenuOpen == 1:
Choice = Menu(["Display value of VAR1", "Display value of VAR2", \
"Change value of VAR1", "Change value of VAR2", "Quit"], \
("What would you like to do? "))
if Choice + 1 == 1:
if VAR1DEF == 1:
VAR1.displayValue()
print VAR1
else:
print "VAR1 is not defined."
if Choice + 1 == 2:
if VAR2DEF == 1:
VAR2.displayValue()
else:
print "VAR2 is not defined."
if Choice + 1 == 3:
chVAR1 = input("What would you like to change VAR1 to? ")
VAR1.changeValue(chVAR1)
VAR1DEF = 1
When I define VAR1 and then tell the program to display the value, it comes up with:
<__main__.Test instance at 0x0250FA80>
To me it looks like VAR1 does not end up being defined. Halp?
Also, the displayValue() method doesn't display the value, it just returns it, to print the returned value, you'd have to do this:
I don't know Python, but that seems kinda counter intuitive, having a function called "displayValue" that doesn't display?
Thanks for the help, can you elaborate on what return does? Also, what is __init__? It's in the tutorial I'm following but doesn't say what it means.
That has nothing to do with Python and everything to do with how he wrote the displayValue method:
It does the same thing it does in virtually every language it shows up in, it returns a value from a function. I can't explain it in simpler terms.
And the tutorial doesn't explain it? That must be a pretty poor tutorial. __init__ is a special built-in method for classes that is called whenever a new instance of a class is created and it's responsible for initializing that instance.
No, it lets you initialize an instance of a class. The initialization of a class *itself* occurs at the class definition (well, metaclasses let you do some weird things, but don't worry about those).
For example, a simple use of __init__ is as follows:
This is a sparse example (a point class would usually come with a lot more functionality for whatever you wanted it for). The __init__ method gets called as part of the initialization sequence when you call Point. Point is the class, Point(0, 0) is an instance of the Point class. The __init__ method also allows arguments to be passed into a new instance. Certainly you could never use the __init__ method. You could also not use classes at all and still write anything, but you're just making things more difficult for yourself if you take this route.
Sorry for being thick, I only started python 2 days ago