Question:
why isn't my simple program running in python?
Larry
2012-02-22 16:25:18 UTC
this is the program i wrote from a book

#chaos.py
def main():
print('Hello and welcome to chaos, this program will illustrate total chaos.')
x = eval(print('Enter a number between 0 and 1: '))
for i in range(10):
x = 3.9 * x * (1-x)
print(x)

main()


and this is my result when i hit f5

Hello and welcome to chaos, this program will illustrate total chaos.
Enter a number between 0 and 1:
Traceback (most recent call last):
File "C:/Python32/chaos", line 9, in
main()
File "C:/Python32/chaos", line 4, in main
x = eval(print('Enter a number between 0 and 1: '))
TypeError: eval() arg 1 must be a string, bytes or code object

I'm using python 3.2 on windows 7
Three answers:
t
2012-02-22 16:46:05 UTC
You are not reading the input correctly. Try this:



def main():

    print('Hello and welcome to chaos, this program will illustrate total chaos.')

    x = float(raw_input('Enter a number between 0 and 1: '))

    for i in range(10):

        x = 3.9 * x * (1-x)

    print(x)



main()
Csssss
2014-01-11 21:44:25 UTC
Did you enter a number between 0 and 1 like .24 or did you just hit enter? You will get that message if you don't input a number into the running program
2016-11-08 12:11:31 UTC
attempt code like (please make effective the first 2 print statements are indented ... which receives lost interior the translation): x = a million if (x % 2) == 0: print "Even" else: print "outstanding" print "accomplished with Conditional"


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...