• 9
• 10
• 9
• 10
• 10

Kinda hard to explain this

This topic is 689 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts


subcores = ["AX43", "JOM10", "BALLS", "AYVOC", "PIZZA", "TITAN"]
cores = ["Fast", "Strong", "Balanced"]
Whole_Item = []
active = 1
item_select = []
core_prompt = ("Select one of them, spell them exactly like it is spelled like." + "\n")
subcores_prompt = ("Select one of the core, spell them exactly like it is spelled like." + "\n")
#####################

print("trash code below!\nThese are the cores available for you:")

for Cheese in cores:
print("\t" + Cheese)

cheese_select = input(core_prompt)

if cheese_select in cores:
print("Adding in " + cheese_select.title() + ".")
else:
print("This isn't in the list, sorry.")
active = 0

if active == 1:
print("Now for the Sub Cores:")

for Item in subcores:
print("\t" + Item)

item_holder = input(subcores_prompt)
if item_holder in subcores:
item_select.append(item_holder)
else:
print("This isn't an item, sorry.")
active = 0

add_item = input("Would you like to add  more items? If so, enter Yes. \n")

while add_item == "Yes" or "yes":
extra = input("Please select another sub core.\n")
if extra in subcores:
print(extra + " has been added!")
item_select.append(extra)
#checks again... if add_item is no or No, go to the if statement below. If Yes or yes, while loop still goes on
if add_item == "No" or "no":
print("This is your finalized core thingy:")
item_select.append(cheese_select)
Whole_Item = item_select[:]
for whole in Whole_Item:
print("\t" + whole)



So I had to do a project for a python book and I made this. The last comment above should tie in with my current problem.

Even if I type in No or No, the while loop still goes on even though it should stop since it requires add_item to be "Yes" or "yes".

(also, do if statements only run once?)

Edited by Calcious

Share on other sites

Also, this is wrong:

    item_holder = input(subcores_prompt)
if item_holder in subcores:
item_select.append(item_holder)
else:
print("This isn't an item, sorry.")
active = 0



You're setting active to 0, you need to be setting add_item_active = 0

Good luck, and keep working at it!

Share on other sites

Just to mention, you can save some horizontal space and accomplish the same thing with a set and the in operator (good if you have lots of options):

while add_item in {"YES", "yes"}:

while add_item == "Yes" or add_item == "yes":
Edited by mrpeed

Share on other sites

I think the python book that I'm using isn't really going in depth.

If you guys can recommend some books that has the right balance of complex and (intuition???), it would be great!

Share on other sites

Does LearnPython.org cover it, or are you looking for something more?

Share on other sites

LearnPython.org seems good but I don't know what some of the words are. I guess I can google those words.

Share on other sites

Very good for beginners. Read the introduction and you'll understand.

Edited by Tanay Karnik

Share on other sites

I think the python book that I'm using isn't really going in depth.

If you guys can recommend some books that has the right balance of complex and (intuition???), it would be great!

"Right balance" is a personal thing. I don't think it is bad if you don't learn everything the first time.

Your primary aim is to be able to express what you want to do. The "or" with two "==" tests does that.

Once you can do that comfortably, you'll start to pick up new and smarter ways of doing things from other people suggesting alternative ways, or code or other books that you read. "in" is one such example, but Python has loads of them. It's an ever lasting process to improve your coding.