PYTHON CODING AND C PROGRAMMING EXAMPLES: PROGRAMMING FOR BEGINNERS by KING J

PYTHON CODING AND C PROGRAMMING EXAMPLES: PROGRAMMING FOR BEGINNERS by KING J

Author:KING, J [KING, J]
Language: eng
Format: epub
Published: 2020-10-10T00:00:00+00:00


Create three lists of numbers, their squares and cubes

Example:

Input:

Start = 1

End = 10

Output:

numbers: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

squares: [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]

cubes : [1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]

Logic

Three lists to declare.

Defining range, here we define beginning with 1 and ending with 10.

Run a loop with the range as range (start, end + 1) and count as loop counter.

Connect the count of the loop counter to the list named numbers, connect the square to the list called squares and add the cube to the list called cubes.

In the end, print out the lists.

PROGRAM

# declare lists

numbers = []

squares = []

cubes = []

# start and end numbers

start = 1

end = 10

# run a loop from start to end+1

for count in range (start, end+1) :

numbers.append (count)

squares.append (count**2)

cubes.append (count**3)

# print the lists

print "numbers: ",numbers

print "squares: ",squares

print "cubes : ",cubes

Output

numbers: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

squares: [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]

cubes : [1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.