• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

is this clumsy?  RSS feed

 
Ranch Hand
Posts: 177
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Particularly this line:
while userChoice != 1 and userChoice !=2 and userChoice !=3 and userChoice !=4 and userChoice !=5 and userChoice != 6 :

The reason im asking is because my teacher mentioned this to get the loop going for the menu
but im sure there is a far more elegant way of doing this
simple sentinel variable for when you got an answer? is that what you would do?

 
wayne brandon
Ranch Hand
Posts: 177
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this is better

 
Greenhorn
Posts: 26
Python VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Wayne,

Yes the "if/elif/else" construct is often used to solve problems like this .  Python does not have a "case..end case" construct in the language so the code shown in the second example is the usual way to address this pythonically.  There are more sophisticated ways to let the data drive the selection, but may I suggest that you let that be a learning experience much further in your Python journey?  🙂
 
My first bit of advice is that if you are going to be a mime, you shouldn't talk. Even the tiny ad is nodding:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!