Page 1 of 1

Python Code- Will my code work?

Posted: Sat Dec 28, 2019 9:00 pm
by gianna1023
Hello! My science fair project is "How Fast Do Computers Calculate Arithmetic Equations?" However, I'm not sure if my code will produce a correct output. I am using a Macbook for my computer, Python for the coding language and IDLE.app for running the code. I reached out to a coding teacher over email, and he showed me a code that worked on his computer. He attached a screenshot, which showed the code did work and produced an accurate output. However, when I entered the code on my computer, it did not work! He was running the code on a program that was not IDLE, and the computer seemed to be a Windows (it did not look as if it was a Mac). How can I change the code to make it work for my family's Macbook and on IDLE? Thank you in advance! This is the code I attempted to use:

from timeit import default_timer as timer

def howlong():
start = timer()
code_to_test = ""
a = range(100000)
b = []

for i in a:
b.append(i*2)
x = 10
y = 40
z = x + y
stop = timer() - start
print(stop)
print(z)

Re: Python Code- Will my code work?

Posted: Mon Jan 06, 2020 8:33 am
by AmyCowen
Have you reviewed this project at Science Buddies?

Programming is not required for the project, but source files are provided as part of the materials, and they may help you better understand how the program works:
https://www.sciencebuddies.org/science- ... #procedure

Amy
Science Buddies
The materials list includes source code for programs in Python and C. The Python program is written to run in Python 3.x, available on Windows, OS X or Linux (try it on a Raspberry Pi!). The C program is written for standard POSIX C, so with minor modifications it should run easily on any machine with a reasonably standard C compiler. If you work with C or C++, then you know what that means.