Python Forum
EASY- creating a for loop with a list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
EASY- creating a for loop with a list
#1
Hi

I need to create a for cycle with a list that returns all values in the list greater than 120. It needs a return statement at the end.

this is as far as I have got :/
for i, aa in  aww:
    if i > 120:
        print(aww)
aww is the list with the integers


thanks to anyone that can help!

rico
Reply
#2
That's the sort of for loop you would have for a list of two item tuples, like [(1, 'a'), (2, 'b'), (3, 'c')]. If your list is just integers, get rid of aa.

If you need a return statement, you need a function. See the functions tutorial link in my signature for the basics.

If you need a return statement, you must need to return something. I'm assuming you need to build a list of the correct values. You'll want to initialize that list to [] before the loop, and when you find a valid i value, you'll want to append that to the list.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
(Nov-30-2018, 12:30 PM)rico Wrote: It needs a return statement at the end.
Moved to Homework. ichabod801 gave plenty of tips on how to move forward, so I'll just leave it at that for now.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Creating guest list manager nickster11 1 2,856 Feb-08-2021, 02:44 PM
Last Post: deanhystad
  Creating a list from a sequence without while-loop schniefen 2 2,331 Apr-01-2019, 07:40 PM
Last Post: nilamo
  Help with while loop creating an infinite loop. FWendeburg 3 3,041 Jan-30-2019, 08:28 PM
Last Post: FWendeburg

Forum Jump:

User Panel Messages

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