mercredi 18 octobre 2017

Why won't my code print the questions inside my if statement?

I'm trying to ask a series of questions and print calculations based on the answers. However, my code will only ask the question outside of the if statement, not the questions within the if statement. Why won't my code ask anything more than the number of lenses? This is my first time using Python 3. Am I using the wrong syntax?

import numpy as np

lensnumber = input("How many lenses are in this system? ")

#single lens
if lensnumber == 1:
#questions
index1 = input("What is the index of refraction of the surrounding material?")
index2 = input("What is the index of refraction of the lens?")
radius11 = input("What is the radius of curvature of the left side of the lens (mm)?")
radius12 = input("What is the radius of curvature of the right side of the lens (mm)?")
diameter1 = input("What is the diameter of the lens (mm)?")
objectdistance1 = input("What is the distance to the object (mm)?")

#calculations
systempower1 = 1 / focallength
focallength1 = 1 / ((index1 - 1) * ((1 / radius11) - (1 / radius12) + (((index1 - 1) * diameter1) / (index1 * radius11 * radius12))))
principalpoint11 = - (focallength1 * (index1 - 1) * diameter1) / (radius12 * index1)
principalpoint12 = - (focallength * (index1 - 1) * diameter1) / (radius11 * index1)
magnification1 = imagedistance1 / objectdistance1
imagedistance1 = 1 / ((1 / focallength1) - (objectdistance1 ** -1))
ffl1 = focallength1 - principalpoint11
bfl1 = focallength1 + principalpoint12

#print
print("")
print("The power of this lens is", systempower1)
print("The focal length of this lens is", focallength1)
print("The first principal point is", principalpoint11)
print("The second principal point is", principalpoint12)
print("The magnification of this lens is", magnification1)
if magnification1 < 0:
    print("The image is not erect.")
else:
    print("The image is erect.")
print("The distance to the image is", imagedistance1)
print("The front focal point is", ffl1)
print("The back focal length is", bfl1)

Aucun commentaire:

Enregistrer un commentaire