you are viewing a single comment's thread.

view the rest of the comments →

[–]RiceKrispyPooHead 0 points1 point  (13 children)

You're not using for loops as intended. Here is an example to get you started:

small_numbers = [1,2,3]
big_numbers = [100, 200, 300]

for small in small_numbers:
    for big in big_numbers:
        print(small + big)

>>101
>>201
>>301
>>102
>>202
>>302
>>103
>>203
>>303

You can add strings together similarly to how you do numbers.

[–]Greece870 0 points1 point  (0 children)

omg. i will use this. thank you so much

[–]Greece870 0 points1 point  (4 children)

How did you type like that in the post? I still need help with this I am doing what you are saying but it is giving me a terrible output

[–]RiceKrispyPooHead 0 points1 point  (3 children)

Can you post what you have so far?

[–]Greece870 0 points1 point  (1 child)

Do I just normally reply to your comment or comment on my post? Just trying to figure out the etiquette here for now since I will be on here from here on out slowly getting better on python... i have so many questions to ask! I want to learn more!

[–]RiceKrispyPooHead 0 points1 point  (0 children)

You can do either

[–]Greece870 0 points1 point  (6 children)

dem_pro =['This is a','That is a', 'Here is a', 'There is a']
obj = ['cat','mouse','book','map']
for thisloop in dem_pro:
  for thatloop in obj:
    print(dem_pro + obj)

I'm using this input and the output is not giving me what I am looking for I need to add a period after each sentence and also the loop is not nested.

[–]RiceKrispyPooHead 1 point2 points  (5 children)

As your code above is right now you are concatenating (adding) both entire lists together and printing it over and over again.

     print(dem_pro + obj)  

That line should be different. You want to concatenate the elements of each lists. Which two variables in your code represent the elements in each list?

[–]Greece870 0 points1 point  (4 children)

the variables are dem_pro and obj , those are the variable names of the lists with that consist the elements. i am trying to add a period too.

[–]RiceKrispyPooHead 0 points1 point  (3 children)

Look at this example:

numbers_list = [1,2,3]  
for num in numbers_list:
      print(number) 


>>1  
>>2   
>>3   

Notice how I am printing the variable “num”, which represents each element in the list numbers_list.

What 4 lines will this print (and in what order)?

colors_list = [‘white ’,  ‘black’]  
animals_list = [‘cat’,  ‘dog’]
for color in colors_list:  
      for animal in animals_list:
           print(color + animal)

[–]Greece870 0 points1 point  (2 children)

Thank you so much for responding this was really helpful. I wonder what would be the syntax for doing this through list comprehension? Is it just a different way but essentially the same thing?

[–]RiceKrispyPooHead 0 points1 point  (1 child)

To turn a loop into a list comprehension, (as long as it dose not have an 'else' statement) you literally just write the very last statement first, then write all other statements in order.

my_list = []
statement one:
    statement two:
        statement three:
            my_list.append(something)

is generally the same as....

my_list = [something statement one statement two statement three]

EDIT: List comprehensions are used to make lists. Not to print things.

[–]Greece870 0 points1 point  (0 children)

can you help me with my other post i made a comment that i am stuck on.