Posts

Showing posts with the label For Loops

Python Loops - For Loop

Image
for loop:           For Loop is used for iterating over a sequence. Collections - a List, Tuple, Dictionary, Set, or String. Its syntax is: for val in sequence:      statement(s)      In the for statement, the variable ‘val’ stores the value of each item on the sequence with every iteration. The loop goes on until all elements are exhausted. Program:  Icecream Shopping - For Loop cart=[ '1.Chocobar' , '2.Funwheel' , '3.Vanilla' , '4.Mango' , '5.Oreo' ] #Function Definition def   menu_card ():      print ( "Menu Card" )      print ( "*********" )      for  i  in  cart:          print (i)          def   shopping ():     tot= 0     num,Amt= 0 , 0     while( 1 ):    ...