Python Forum
Is there a goto like there is in BASIC?
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is there a goto like there is in BASIC?
#1
I did a lot of programming in MS Visual BASIC 6 way back when.  Now I'm getting up to speed in Python.  To learn Python's equivalent of If/Then/ElseIf, I've written the following code:

intLangChoice = int(input("Choose your language, 1 for French, 2 for English, 3 for German, or 4 for Spanish. "))
if intLangChoice == 1:
    print("On parle en français aujoud'hui.")
elif intLangChoice == 2:
    print("We're speaking in English today.")
elif intLangChoice == 3:
    print("Wir sprechen heute auf Deutsch.")
elif intLangChoice == 4:
    print("Hoy hablamos en español.") 
else:
    print("You didn't choose a language.")
It's a good start.  It runs.  However, I would like to make them choose a language if they put something in other than 1, 2, 3, or 4.  If they put in 5 or higher, they'll get "You didn't choose a language."  At that point, I'd like to send them back to the beginning of the code where it says, "Choose your language, 1 for French, 2 for English, 3 for German, or 4 for Spanish." 

If I mixed in the BASIC "goto" command with this code, it would be like this:

TheTop: 
intLangChoice = int(input("Choose your language, 1 for French, 2 for English, 3 for German, or 4 for Spanish. "))
if intLangChoice == 1:
 print("On parle en français aujoud'hui.")
elif intLangChoice == 2:
 print("We're speaking in English today.")
elif intLangChoice == 3:
 print("Wir sprechen heute auf Deutsch.")
elif intLangChoice == 4:
 print("Hoy hablamos en español.")
else:
 print("You didn't choose a language.")
  GoTo TheTop
I googled around, but what I found didn't run.
Reply


Messages In This Thread
Is there a goto like there is in BASIC? - by Luke_Drillbrain - Apr-20-2017, 09:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  goto jmabrito 34 10,447 Feb-18-2021, 09:55 PM
Last Post: jmabrito
  How to make input goto a different line mxl671 2 2,488 Feb-04-2020, 07:12 PM
Last Post: Marbelous
  goto problem Skaperen 1 2,753 Jan-27-2018, 01:11 PM
Last Post: stranac
  Go up script/menu(a goto command) foxtreat 7 8,275 Apr-24-2017, 05:58 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

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