Posts: 1
Joined: Sat Dec 28, 2019 8:40 pm
Occupation: Student

Python Code- Will my code work?

Postby gianna1023 » Sat Dec 28, 2019 9:00 pm

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 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:
x = 10
y = 40
z = x + y
stop = timer() - start

Site Admin
Posts: 387
Joined: Mon Aug 22, 2016 4:39 pm
Occupation: Administrator

Re: Python Code- Will my code work?

Postby AmyCowen » Mon Jan 06, 2020 8:33 am

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: ... #procedure

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.

Return to “Grades 9-12: Math and Computer Science”