0% found this document useful (0 votes)
13 views1 page

Marble Count in Python Program

This Python script simulates having a set number of marbles that are subtracted from one by one in a loop. It prints out the number of remaining marbles on each iteration using a string of dots to represent the marbles visually, and warns when the number drops below 4. Once all marbles are subtracted, the loop ends.

Uploaded by

gabonest82
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views1 page

Marble Count in Python Program

This Python script simulates having a set number of marbles that are subtracted from one by one in a loop. It prints out the number of remaining marbles on each iteration using a string of dots to represent the marbles visually, and warns when the number drops below 4. Once all marbles are subtracted, the loop ends.

Uploaded by

gabonest82
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd

#!

/usr/bin/env python3

marbles = 10 #You start out with 10 marbles


marble_dots = "**********" #Pretend these are ten marbles

while (marbles > 0):

#This prints out how many marbles you have left.


# We have to say str(marbles) because marbles is a number
# and we want to use it in a string (letters and other characters)
print(marble_dots[:marbles])
print("You have " + str(marbles) + " marbles left.")

if (marbles < 4):


print("Warning: You are running low on marbles!!")

#This is another way of saying "Subtract 1 from the marbles variable"


# It is logically the same as writing "marbles = marbles - 1", just shorter
marbles -= 1
marble_dots[:marbles]

# Make a newline, so there's an empty line before the next time we run this loop
print("")

#This is *NOT* indented, and is therefore not part of the above loop.
#Just sayin'

You might also like