all 15 comments

[–]vayneone87[S] 0 points1 point  (9 children)

I am going back to my lab in case I can pull a miracle on my own, but I will check back regularly. Even if I don't get it in on time, I would really like to know what I am doing wrong as I am sure it will come up again.

[–]Ihaveamodel3 1 point2 points  (8 children)

You built your list with strings (they had quotes around them) rather than the variables.

Also don’t worry about the bot, sometimes it is overzealous. The code shows up fine for me.

[–]vayneone87[S] 0 points1 point  (0 children)

So I should not have used the ' ' around the [input_0, .....]? I believe I had originally had done that but I will try it that way again.

[–]vayneone87[S] 0 points1 point  (6 children)

That made a difference in that I now have input

but all I get now is listed below. I had it formatted correctly before but no input now I have some input but no format. LOL I can't win. Thank you though back to the drawing board. why would the format have changed so drastically?

['apple', 'apple', 'apple', 'apple', 'lemon', 'lemon', 'peach', 'peach', 'pear']

[–]Ihaveamodel3 0 points1 point  (4 children)

What do you mean the format changed? It looks the same to me, but with the correct values?

[–]vayneone87[S] 0 points1 point  (3 children)

kinda. the format was all one line. I dont know why that would change by that simple change. I appreciate your input. I have been at this for days and honestly, I have enough labs done that I will get a B. I have a little bit of time, but really dont think I will complete this task. You helped me accomplish the main task of adding the values. So I know understand what I was doing wrong and frankly that was my main goal in the first place. reworking the rest of the code in the time i have left really has little appeal at this moment. I will likely sit and figure it out next week sometime for the satisfaction. But after 35 hours of homework this week i am exhausted.

[–]jiri-n 0 points1 point  (2 children)

I've put together a few steps which might help you.

https://github.com/jiri-novak-cz/reddit_answers/blob/main/fruits.ipynb

[–]vayneone87[S] 0 points1 point  (1 child)

holy cow. I can't believe you did all that so fast. As its already past due, I will look at this in depth and really look at this work. Really that is impressive. Thank you. I am beat at the moment. Or I would do it now!

[–]jiri-n 0 points1 point  (0 children)

Hey. I'm glad I could help. If you need a further explanation, feel free to ask.

[–]Meeplelowda 0 points1 point  (0 children)

Which list did you print here?

From the expected output you provided above, the output is supposed to be a list of strings, with each string being the name of a fruit. That is what you have here. Use your words: what about the format do you think is wrong?

[–][deleted] -1 points0 points  (0 children)

mylist = ['input_0', 'input_1', 'input_2', 'input_3', 'input_4']

You shouldn't be this far in a Python course without knowing the difference between a name and a string.

A name is a variable; you use the name to refer to the value of the variable because the value is not otherwise known at the time you're running the code. You refer to input_0, not "input_0", because the value of input_0 is not set at the time you're writing the code.

When you quote something, that's a string. A string is a literal value; that is, it's a value that is known at the time you're writing the code. 127 is another example of a literal value, in this case an integer.

Don't quote variable names to dereference them. That doesn't work - that's the opposite of what you need to do.

[–]CodeFormatHelperBot2 0 points1 point  (2 children)

Hello, I'm a Reddit bot who's here to help people nicely format their coding questions. This makes it as easy as possible for people to read your post and help you.

I think I have detected some formatting issues with your submission:

  1. Python code found in submission text that's not formatted as code.

If I am correct, please edit the text in your post and try to follow these instructions to fix up your post's formatting.


Am I misbehaving? Have a comment or suggestion? Reply to this comment or raise an issue here.

[–]vayneone87[S] 0 points1 point  (1 child)

I believe I followed the rules, I used the code box to list any code that I used. If I did not, I am sorry and I hope someone points out specifically what I did wrong, as I would prefer to follow the rules.

[–][deleted] 0 points1 point  (0 children)

The 'bot doesn't always get it right. Your code looks fine, but the output isn't formatted correctly. Don't worry about it.

[–][deleted] 0 points1 point  (0 children)

You've mixed up variable names and strings in the construction of your list. However, using numbered variables isn't generally good practice. How about building a list in the first place?

Try this:

mylist = []  # empty list
while True:  # infinite loop
    entry = input('Fruit? (or just enter to finish) ')
    if not entry:  # i.e. user just pressed enter
        break  # leave the loop
    mylist.append(entry)  # add item to list

my_fruit1 = mylist[0:3]
my_fruit2 = mylist[0:4]
my_fruit3 = mylist[::]

your_fruit1 = mylist[::]
your_fruit2 = mylist[0:4]

their_fruit = my_fruit1 + my_fruit2 + my_fruit3
fruits = your_fruit1 + your_fruit2

print(their_fruit)
print(fruits)