-
Notifications
You must be signed in to change notification settings - Fork 199
/
Copy pathAreaScanner.py
39 lines (36 loc) · 1.82 KB
/
AreaScanner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
""" From "COMPUTATIONAL PHYSICS" & "COMPUTER PROBLEMS in PHYSICS"
by RH Landau, MJ Paez, and CC Bordeianu (deceased)
Copyright R Landau, Oregon State Unv, MJ Paez, Univ Antioquia,
C Bordeianu, Univ Bucharest, 2017.
Please respect copyright & acknowledge our work."""
# AreaScanner: examples of use of formated output
# and reading input from the keyboard. Also: Input/Output with files
import math
name= raw_input( 'Key in your name: ') #raw_input is good for strings
print "Hi ",name
radius=input('Enter a radius: ') # works with numerical values
print 'you entered radius= %8.5f'%radius # formatted output
name= raw_input('Key in another name: ') # raw_input good for strings
radius=input('Enter a radius: ')
print 'Enter new name and r in file Name.dat'
inpfile=open('Name.dat','r') # to read from file Name.dat
for line in inpfile:
line=line.split() # splits components of line
name=line[0] # first entry in the list
print " Hi %10s" %(name) # print Hi plus first entry
r=float(line[1]) # second entry convert to float
print " r = %13.5f" %(r) # converts x to float and print it
inpfile.close()
A=math.pi*r**2 # use radius to find circles's area
print "Done, look in A.dat\n"
outfile=open('A.dat','w')
outfile.write( 'r= %13.5f\n'%(r))
outfile.write('A = %13.5f\n'%(A))
outfile.close()
print 'r = %13.5f'%(r) # screen output
print 'A = %13.5f'%(A)
print 'Now example of integer input '
age=int(input ('Now key in your age as an integer: '))
print "age: %4d years old, you don't look it!\n"%(age)
print "Press a character to finish"
s=raw_input()