Geek, uncensored

Learning Center

July 3, 2012

Python Programming-Source Code-Print Command-Loops

All comments are defined by “#”. When entered in the program, it should be displayed as red text that doesn’t affect the program at all. The indentions are not entered on here, be sure to remember that when looking at this post.

Modify the Chaos program so that the number of values to print is determined by the user.

#Define the main function for easy access in the Shell
#Print what the purpose of this function is
#Get input from the user for a number between 0 and 1
#Find out from the use how many numbers they would like to print
#This input will be labeled as “n”. We must use the “eval” to make sure
#That the number the user enters is evaluated as an integer and not a string
#We change the range to “n” which is the amount of times that the user
#Specified. Remember, this will only work if the n is evaluated as an integer
#the formula
#Print x each time the loop is run.
[code]def main():

print(“This program illustrates a chaotic function”)

x = eval(input(“Enter a number between 0 and 1: “))

n = eval(input(“How many numbers should I print? “))

for i in range (n):

x = 3.9 * x * (1-x)



About the Author

Blogger, Programmer, Zombie Survivalist Expert, Girl Gamer, Pianist, Super Geek, the Epitome of Awesome. Saying the things your mind tells you not to.


Be the first to comment!

You must be logged in to post a comment.