0% found this document useful (0 votes)
10 views2 pages

For Loop Printed Preview

Python loop

Uploaded by

Quoc Bao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

For Loop Printed Preview

Python loop

Uploaded by

Quoc Bao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 2
PYTHON FOR LOOPS name = input(“Enter your name: ") for x in range(1,3): print (name) ‘This will ask the user to enter their name and it will use a loop to display it. The variable “x” isa temporary variable used to count the position in the loop. The range section states the starting value of x and the end value of x. When the end value (in this case 3) is reached the loop will stop so this loop will display the name twice as when it gets to the third loop it will stop before the name is displayed for x in range(1,10,2): print (x) ‘This program will display the value of x and in this instance it will be 1, 3, 5, 7, 9 as it wills start at 1, end when uname (cs Ny tep up in values of 2 word = sommes a word; roe for x in word: print (x) et aaa wore Sg andi N Using the oN statement Read each for loop and write the output you will get. You may want to type it into Python and test it out to help you get the answer. focal emt for x in range (1,10): print (x) for x in range(1,10,2): print (x) for x in range(100,0,-10): print (x) for x in range(0,21,5): print (x) Paget (© Nichola Lacey 2018 Correcting Code The user wants ta display a count dawn from L0to 1 and then cisplay “Blast Of” but the fallowing code is not working, Why isthis.? xr x in range(10,1,-1): a

You might also like