User:Guy vandegrift/S/3

From Wikiversity
Jump to navigation Jump to search


## Boilerplate code
import random, math
def whatis(st, x):
    print(st+' value=',repr(x),type(x))
    return st+' value='+repr(x)+repr(type(x))
###################################### end boilerplate

## step 0. IMPORTANT: Declare attribution by replacing everything after "Attribution:" 
##   in this string defined as myAttribution. (In Python the triple quotes permits linebreaks)
myAttribution='''Attribution: Here is where you write your attribution.  It is
recommended that students become a member of Wikiversity/Wikipedia and select
an anonymous username.  You have three good choices:
*CC-BY-SA by user:xxx  (where xxx is your username).  
*Public Domain (with or without a name)
*From OpenStax xxx (include name, chapter, url link to textbook)
You are encouraged to combine a CC-BY-SA and an OpenStax attribution
No problem can be accepted without an attribution'''
print(myAttribution)

## step 1. import functions as needed:
from math import log, exp, log10, atan, degrees, sin, cos, tan, asin, acos, atan, pi,\
     hypot


## step 2. Declare variables, avoiding magic words:
#   firstRendition questionString   insertImage    QuesVar
#   prefix2answer  answer2question  myAttribution  st 
#   offByFactors   detractorsOff    units2answer    

k=8.99e9
e=1.602e-19
a=2e-7#meters
b=2*a

## step 3. Optional print and whatis statements:
## print('k is',k)
## print(k,e,a,b,q1,q2,q3)
## whatis('k',k)


## step 4. Solve problem avoiding magic words:
#   firstRendition  questionString  insertImage QuesVar
#   prefix2answer   answer2question units2answer
#   offByFactors    detractorsOffBy insertImage st
#######################################

q1=2*e
q2=3*e
q3=5*e
E1= ( k * q1 ) / (a**2)
E3= ( k * q3 ) / (b**2)
E=hypot(E1,E3)
Force=q2*E

##declare answer and units:
answer2question=Force
units2answer=' N'
##################################
## State question using magic word "st"
st='\nQuestion: ' 
st+='A charge of '+str(q1) + 'C lies on the y-axis at y= '
st+=str(a)+'m and a charge of' + str(q3) + 'C '
st+='lies on the x axis at x= '
st+=str(b) +'m. What is the force on a charge '
st+='of '+str(q2)+' C at the origin?\n'

## STOP HERE ##
print(st)
print('Answer: '+str(answer2question)+units2answer)