Python Forum
Python, While loop & lists
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python, While loop & lists
#2
The while loop is easy. If it's based on a variable, you just set that variable to False:

while carry_on:
    ...
    if operation[0].lower() == 'q':
        carry_on = False
Depending on the structure of your program, you can often simplify this to while operation[0].lower() != 'q':.

If you can expect a list like ['Add', '8', 'and', '1'], you just need to get the second and fourth items (with zero-indexing these are operation[1] and operation [3]), convert them to numbers with the built-in int(), and add them together.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
Python, While loop & lists - by jaki - Jun-28-2018, 06:48 AM
RE: Python, While loop & lists - by ichabod801 - Jun-28-2018, 11:14 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Hot mess with functions, lists, and while loop johneven 7 4,886 Jul-15-2019, 09:47 PM
Last Post: johneven

Forum Jump:

User Panel Messages

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