Skip to content
Snippets Groups Projects
Commit 47a7d596 authored by cprutean's avatar cprutean
Browse files

Replace ReadScope.ipynb

parent 6a2222c3
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id:1c15801d tags: %% Cell type:markdown id:1c15801d tags:
# Read Text File # Read Scope
%% Cell type:code id:004b1951 tags: %% Cell type:code id:004b1951 tags:
``` python ``` python
""""
Example to show reading a global variable across main and a function.
""" """
Read a text file and print out to terminal import math
""" wavelength = 0.65 # Define a global float
def main():
filename = str(input("Input file name : "))
filein = open(filename, "r") # Open file for reading
input_data = filein.readlines() # Read in data as list of strings def planck(temperature):
c_one = 5.029e6 # 2 h c^2
c_two = 1.44e4 # hc/k
#
# Can access wavelength inside function
val = c_one/math.pow(wavelength,5)*(1.0/(math.exp(c_two/(wavelength*temperature)) - 1.0))
return val
for line in input_data: # Scan through writing lines
print(line) # Note extra "\n" problem
for line in input_data:
print (line[:-1]) # This removes the last character def main():
#
# Can access wavelength inside main
print("Plank intensity at : " + str(wavelength))
for t in range(300,340):
val = planck(t)
print("Value at : " + str(t) + " is " + str(val))
main() main()
``` ```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment