Creating a loop using Python (to simulate a “goto” like solution)
up vote
-1
down vote
favorite
Here is my approach to simulate a goto sequence. Is there a more eloquent way?
PS: the idea with storing the variable in a class variable was just for fun (because of the .(format()) accessing story.
n=0
while n==0:
print("Whats your height?")
height=input()
print("Whats your age?")
age=input()
class loop:
h=height
a=age
print("Your height is {answer.h}".format(answer=loop()))
print("Would you like to continue?")
answer=input()
if answer=="yes":
++n
print("alright ONE MORE TIME!")
else:
print("see you")
python json loops if-statement
add a comment |
up vote
-1
down vote
favorite
Here is my approach to simulate a goto sequence. Is there a more eloquent way?
PS: the idea with storing the variable in a class variable was just for fun (because of the .(format()) accessing story.
n=0
while n==0:
print("Whats your height?")
height=input()
print("Whats your age?")
age=input()
class loop:
h=height
a=age
print("Your height is {answer.h}".format(answer=loop()))
print("Would you like to continue?")
answer=input()
if answer=="yes":
++n
print("alright ONE MORE TIME!")
else:
print("see you")
python json loops if-statement
damnit i forgot the "break" after "..see you" xD
– Günay Özcan
Sep 8 at 22:45
3
What are you trying to do? What about this needs a goto?
– jmucchiello
Sep 8 at 22:49
actually its not about to become a "goto", since im new in python btw. in programming i remembered from c(i think) a thing called goto. But after a lot of research i discovered that goto is..crap(summary). so my curiosity is more like "is there a way to pull the code above in a more smart way down
– Günay Özcan
Sep 8 at 22:52
1
If you forgot something, you can edit your question to add it.
– das-g
Sep 8 at 23:04
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
Here is my approach to simulate a goto sequence. Is there a more eloquent way?
PS: the idea with storing the variable in a class variable was just for fun (because of the .(format()) accessing story.
n=0
while n==0:
print("Whats your height?")
height=input()
print("Whats your age?")
age=input()
class loop:
h=height
a=age
print("Your height is {answer.h}".format(answer=loop()))
print("Would you like to continue?")
answer=input()
if answer=="yes":
++n
print("alright ONE MORE TIME!")
else:
print("see you")
python json loops if-statement
Here is my approach to simulate a goto sequence. Is there a more eloquent way?
PS: the idea with storing the variable in a class variable was just for fun (because of the .(format()) accessing story.
n=0
while n==0:
print("Whats your height?")
height=input()
print("Whats your age?")
age=input()
class loop:
h=height
a=age
print("Your height is {answer.h}".format(answer=loop()))
print("Would you like to continue?")
answer=input()
if answer=="yes":
++n
print("alright ONE MORE TIME!")
else:
print("see you")
python json loops if-statement
python json loops if-statement
edited Nov 10 at 23:31
halfer
14.2k757106
14.2k757106
asked Sep 8 at 22:42
Günay Özcan
11
11
damnit i forgot the "break" after "..see you" xD
– Günay Özcan
Sep 8 at 22:45
3
What are you trying to do? What about this needs a goto?
– jmucchiello
Sep 8 at 22:49
actually its not about to become a "goto", since im new in python btw. in programming i remembered from c(i think) a thing called goto. But after a lot of research i discovered that goto is..crap(summary). so my curiosity is more like "is there a way to pull the code above in a more smart way down
– Günay Özcan
Sep 8 at 22:52
1
If you forgot something, you can edit your question to add it.
– das-g
Sep 8 at 23:04
add a comment |
damnit i forgot the "break" after "..see you" xD
– Günay Özcan
Sep 8 at 22:45
3
What are you trying to do? What about this needs a goto?
– jmucchiello
Sep 8 at 22:49
actually its not about to become a "goto", since im new in python btw. in programming i remembered from c(i think) a thing called goto. But after a lot of research i discovered that goto is..crap(summary). so my curiosity is more like "is there a way to pull the code above in a more smart way down
– Günay Özcan
Sep 8 at 22:52
1
If you forgot something, you can edit your question to add it.
– das-g
Sep 8 at 23:04
damnit i forgot the "break" after "..see you" xD
– Günay Özcan
Sep 8 at 22:45
damnit i forgot the "break" after "..see you" xD
– Günay Özcan
Sep 8 at 22:45
3
3
What are you trying to do? What about this needs a goto?
– jmucchiello
Sep 8 at 22:49
What are you trying to do? What about this needs a goto?
– jmucchiello
Sep 8 at 22:49
actually its not about to become a "goto", since im new in python btw. in programming i remembered from c(i think) a thing called goto. But after a lot of research i discovered that goto is..crap(summary). so my curiosity is more like "is there a way to pull the code above in a more smart way down
– Günay Özcan
Sep 8 at 22:52
actually its not about to become a "goto", since im new in python btw. in programming i remembered from c(i think) a thing called goto. But after a lot of research i discovered that goto is..crap(summary). so my curiosity is more like "is there a way to pull the code above in a more smart way down
– Günay Özcan
Sep 8 at 22:52
1
1
If you forgot something, you can edit your question to add it.
– das-g
Sep 8 at 23:04
If you forgot something, you can edit your question to add it.
– das-g
Sep 8 at 23:04
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Solution
class Person():
def __init__(self,name, height, age):
self.name = name
self.height = height
self.age = age
while True:
name = input("What's your name?n")
height = input("What's your height?n")
age = input("What's your age?n")
user = Person(name, height, age)
print(f"nHello {(user.name).title()}, your height is {user.height} and you are"
f" {user.age} years old!")
answer = input("nWould you like to continue?('yes' or 'no')n")
if answer == 'yes':
print("alright ONE MORE TIME!")
continue
else:
print("See you!")
break
This is how I would go about this, although there is no reason to have a class here for what you are trying to accomplish, but since you had it in there I'm assuming you were using it as practice, so I threw in a class here as well.
Edit
Ah you mentioned the class
was for fun, not claiming I used class
in the best fashion here but it's an improvement for the way you attempted, would definitely look over proper utilization of class
.
thank you for the support man, your code looks neat :D
– Günay Özcan
Sep 9 at 11:01
Your welcome, but you are dong me a service as well! Helping others is a good way to learn, since you need to try to get a even better understanding to explain to someone else. Take time on here to look around and attempt to solve/learn from others questions, it helps.
– vash_the_stampede
Sep 9 at 12:10
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Solution
class Person():
def __init__(self,name, height, age):
self.name = name
self.height = height
self.age = age
while True:
name = input("What's your name?n")
height = input("What's your height?n")
age = input("What's your age?n")
user = Person(name, height, age)
print(f"nHello {(user.name).title()}, your height is {user.height} and you are"
f" {user.age} years old!")
answer = input("nWould you like to continue?('yes' or 'no')n")
if answer == 'yes':
print("alright ONE MORE TIME!")
continue
else:
print("See you!")
break
This is how I would go about this, although there is no reason to have a class here for what you are trying to accomplish, but since you had it in there I'm assuming you were using it as practice, so I threw in a class here as well.
Edit
Ah you mentioned the class
was for fun, not claiming I used class
in the best fashion here but it's an improvement for the way you attempted, would definitely look over proper utilization of class
.
thank you for the support man, your code looks neat :D
– Günay Özcan
Sep 9 at 11:01
Your welcome, but you are dong me a service as well! Helping others is a good way to learn, since you need to try to get a even better understanding to explain to someone else. Take time on here to look around and attempt to solve/learn from others questions, it helps.
– vash_the_stampede
Sep 9 at 12:10
add a comment |
up vote
0
down vote
Solution
class Person():
def __init__(self,name, height, age):
self.name = name
self.height = height
self.age = age
while True:
name = input("What's your name?n")
height = input("What's your height?n")
age = input("What's your age?n")
user = Person(name, height, age)
print(f"nHello {(user.name).title()}, your height is {user.height} and you are"
f" {user.age} years old!")
answer = input("nWould you like to continue?('yes' or 'no')n")
if answer == 'yes':
print("alright ONE MORE TIME!")
continue
else:
print("See you!")
break
This is how I would go about this, although there is no reason to have a class here for what you are trying to accomplish, but since you had it in there I'm assuming you were using it as practice, so I threw in a class here as well.
Edit
Ah you mentioned the class
was for fun, not claiming I used class
in the best fashion here but it's an improvement for the way you attempted, would definitely look over proper utilization of class
.
thank you for the support man, your code looks neat :D
– Günay Özcan
Sep 9 at 11:01
Your welcome, but you are dong me a service as well! Helping others is a good way to learn, since you need to try to get a even better understanding to explain to someone else. Take time on here to look around and attempt to solve/learn from others questions, it helps.
– vash_the_stampede
Sep 9 at 12:10
add a comment |
up vote
0
down vote
up vote
0
down vote
Solution
class Person():
def __init__(self,name, height, age):
self.name = name
self.height = height
self.age = age
while True:
name = input("What's your name?n")
height = input("What's your height?n")
age = input("What's your age?n")
user = Person(name, height, age)
print(f"nHello {(user.name).title()}, your height is {user.height} and you are"
f" {user.age} years old!")
answer = input("nWould you like to continue?('yes' or 'no')n")
if answer == 'yes':
print("alright ONE MORE TIME!")
continue
else:
print("See you!")
break
This is how I would go about this, although there is no reason to have a class here for what you are trying to accomplish, but since you had it in there I'm assuming you were using it as practice, so I threw in a class here as well.
Edit
Ah you mentioned the class
was for fun, not claiming I used class
in the best fashion here but it's an improvement for the way you attempted, would definitely look over proper utilization of class
.
Solution
class Person():
def __init__(self,name, height, age):
self.name = name
self.height = height
self.age = age
while True:
name = input("What's your name?n")
height = input("What's your height?n")
age = input("What's your age?n")
user = Person(name, height, age)
print(f"nHello {(user.name).title()}, your height is {user.height} and you are"
f" {user.age} years old!")
answer = input("nWould you like to continue?('yes' or 'no')n")
if answer == 'yes':
print("alright ONE MORE TIME!")
continue
else:
print("See you!")
break
This is how I would go about this, although there is no reason to have a class here for what you are trying to accomplish, but since you had it in there I'm assuming you were using it as practice, so I threw in a class here as well.
Edit
Ah you mentioned the class
was for fun, not claiming I used class
in the best fashion here but it's an improvement for the way you attempted, would definitely look over proper utilization of class
.
edited Sep 8 at 23:12
answered Sep 8 at 23:06
vash_the_stampede
3,7591319
3,7591319
thank you for the support man, your code looks neat :D
– Günay Özcan
Sep 9 at 11:01
Your welcome, but you are dong me a service as well! Helping others is a good way to learn, since you need to try to get a even better understanding to explain to someone else. Take time on here to look around and attempt to solve/learn from others questions, it helps.
– vash_the_stampede
Sep 9 at 12:10
add a comment |
thank you for the support man, your code looks neat :D
– Günay Özcan
Sep 9 at 11:01
Your welcome, but you are dong me a service as well! Helping others is a good way to learn, since you need to try to get a even better understanding to explain to someone else. Take time on here to look around and attempt to solve/learn from others questions, it helps.
– vash_the_stampede
Sep 9 at 12:10
thank you for the support man, your code looks neat :D
– Günay Özcan
Sep 9 at 11:01
thank you for the support man, your code looks neat :D
– Günay Özcan
Sep 9 at 11:01
Your welcome, but you are dong me a service as well! Helping others is a good way to learn, since you need to try to get a even better understanding to explain to someone else. Take time on here to look around and attempt to solve/learn from others questions, it helps.
– vash_the_stampede
Sep 9 at 12:10
Your welcome, but you are dong me a service as well! Helping others is a good way to learn, since you need to try to get a even better understanding to explain to someone else. Take time on here to look around and attempt to solve/learn from others questions, it helps.
– vash_the_stampede
Sep 9 at 12:10
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52239963%2fcreating-a-loop-using-python-to-simulate-a-goto-like-solution%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
damnit i forgot the "break" after "..see you" xD
– Günay Özcan
Sep 8 at 22:45
3
What are you trying to do? What about this needs a goto?
– jmucchiello
Sep 8 at 22:49
actually its not about to become a "goto", since im new in python btw. in programming i remembered from c(i think) a thing called goto. But after a lot of research i discovered that goto is..crap(summary). so my curiosity is more like "is there a way to pull the code above in a more smart way down
– Günay Özcan
Sep 8 at 22:52
1
If you forgot something, you can edit your question to add it.
– das-g
Sep 8 at 23:04