#๐ New to python....displaying Items in list
38 messages ยท Page 1 of 1 (latest)
@frigid lion
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
cat
this is the current output to give an idea of the goal. it should be the height of each instead of "10-12in" for both
A problem with sharing screenshots is it is difficult to ctrl+f "compareTwoItems" in a screenshot.
two lists is a requirement
ok
idk the command for pasting
you need to get the indices of the breeds then, and use them in that function
!paste
If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.
!code or this
!e
cats = ["meow", "purr", "nap"]
cat_stats = [[5, 1], [3, 2], [4, 0]]
print(cat_stats[cats.index("purr")])
@mortal forge :white_check_mark: Your 3.12 eval job has completed with return code 0.
[3, 2]
do you see how you can use catData[cats.index("Main Coon")] to access that particular cat?
given that you got Main Coon from the user
I'm not sure what your findIndex function is supposed to do
the iteration is pointless. if both cats are there it will return 0, otherwise it will return -1 after making the same check needlessly many times
if index != -1:
if comp1 in cats and comp2 in cats:
# ...
else:
print("One or both of the cat breeds were not found.")
also, here you are doing the job of findIndex again
try this:
def compareTwoItems(comp1, comp2, cats, catData):
a = "Adult Height"
w = "Adult Weight"
p = "Average Price"
if comp1 in cats and comp2 in cats:
cat1 = catData[cats.index(comp1)]
cat2 = catData[cats.index(comp2)]
print(cat1, cat2)
print(f"{a:15}{w:15}{p:15}")
data = input("What data would you like to compare?: ")
if data == a:
print(f"{catData[index][0]:20}{catData[index][0]:20}")
elif data == w:
print(f"{catData[index][1]:20}{catData[index][1]:20}")
elif data == p:
print(f"{catData[index][2]:20}{catData[index][2]:20}")
else:
print("Comparison not found (check casing)")
else:
print("Invalid cat breeds provided.")
cats.index(comp1) finds the index of comp1 in cats, then by calling catData[] on that index you find the stats of that cat
if you want to keep working with your own structure, you could make findIndex do the job of finding the indices of both cats
That does make sense
I get an error because 'index' is not defined
would that mean I'd have to make findIndex do that anyways?
!e
foo = ["a", "b", "c"]
print(foo.index("b"))
@mortal forge :white_check_mark: Your 3.12 eval job has completed with return code 0.
1
I haven't used it much tbf, but I would expect your python should support it
it's ok if you want to look for it yourself though
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.
๐ New to python....displaying Items in list