Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- from math import sin
- from math import pi as n
- print(" Welcome to Refraction Calculator! ")
- print(" Created by:Sajid Ul Islam ")
- print(" =========================================== ")
- def refraction_calculator():
- print('What do you want to find?)')
- print("1.Snel's law\n2.Relative refraction")
- user_input1 = input('Your answer:')
- if user_input1 == '1':
- print('What do you want to find?')
- print('1.Sin1\n2.Sin2\n3.n1\n4.n2')
- user_input = input('Your answer:')
- if user_input == "1":
- Sin2 = float(input('Enter the value of Sin2:')) * n / 180
- b = math.sin(Sin2)
- n1 = float(input('Enter the value of n1:'))
- n2 = float(input('Enter the value of n2:'))
- Result = ((b / n2) * n1)
- print("Sin1:", Result)
- elif user_input == "2":
- Sin1 = float(input('Enter the value of Sin1:')) * n / 180
- b = math.sin(Sin1)
- n1 = float(input('Enter the value of n1:'))
- n2 = float(input('Enter the value of n2:'))
- Result = ((b * n1) / n2)
- print('Sin2:', Result)
- elif user_input == '3':
- Sin1 = float(input('Enter the value of Sin1:')) * n / 180
- b = math.sin(Sin1)
- Sin2 = float(input('Enter the value of Sin2:')) * n / 180
- c = math.sin(Sin2)
- n2 = float(input('Enter the value of n2:'))
- Result = ((c * n2) / b)
- print('n1:', Result)
- elif user_input == '4':
- Sin1 = float(input('Enter the value of Sin1:')) * n / 180
- b = math.sin(Sin1)
- Sin2 = float(input('Enter the value of Sin2:')) * n / 180
- c = math.sin(Sin2)
- n1 = float(input('Enter the value of n1:'))
- Result = ((b * n1) / c)
- print('n2:', Result)
- if user_input1 == '2':
- print('Which relative refraction do you want to find?')
- print('1.n1/n2 \n2.n2/n1')
- user_input = input('Your answer:')
- list2 = [1.00, 1.00029, 1.33, 1.52, 2.42]
- if user_input == '1':
- print('1.Zero\n2.Air\n3.Water\n4.Glass\n5.Diamond')
- n1 = str(input('Enter the number of the name of n1:'))
- if n1 == '1':
- r1 = list2[0]
- print("Refraction value:", r1)
- elif n1 == '2':
- r1 = list2[1]
- print("Refraction value:", r1)
- elif n1 == '3':
- r1 = list2[2]
- print("Refraction value:", r1)
- elif n1 == '4':
- r1 = list2[3]
- print("Refraction value:", r1)
- elif n1 == '5':
- r1 = list2[4]
- print("Refraction value:", r1)
- n2 = str(input('Enter the number of the name of n2:'))
- if n2 == '1':
- r2 = list2[0]
- print('Reflection value:', r2)
- if n2 == '2':
- r2 = list2[1]
- print("Refraction value:", r2)
- elif n2 == '3':
- r2 = list2[2]
- print("Refraction value:", r2)
- elif n2 == '4':
- r2 = list2[3]
- print("Refraction value:", r2)
- elif n2 == '5':
- r2 = list2[4]
- print("Refraction value:", r2)
- s = r1 / r2
- print('n1/n2:', s)
- if user_input == '2':
- print('1.Zero\n2.Air\n3.Water\n4.Glass\n5.Diamond')
- n1 = str(input('Enter the number of the name of n1:'))
- if n1 == '1':
- r1 = list2[0]
- print("Refraction value:", r1)
- elif n1 == '2':
- r1 = list2[1]
- print("Refraction value:", r1)
- elif n1 == '3':
- r1 = list2[2]
- print("Refraction value:", r1)
- elif n1 == '4':
- r1 = list2[3]
- print("Refraction value:", r1)
- elif n1 == '5':
- r1 = list2[4]
- print("Refraction value:", r1)
- n2 = str(input('Enter the number of the name of n2:'))
- if n2 == '1':
- r2 = list2[0]
- print('Reflection value:', r2)
- if n2 == '2':
- r2 = list2[1]
- print("Refraction value:", r2)
- elif n2 == '3':
- r2 = list2[2]
- print("Refraction value:", r2)
- elif n2 == '4':
- r2 = list2[3]
- print("Refraction value:", r2)
- elif n2 == '5':
- r2 = list2[4]
- print("Refraction value:", r2)
- s = r2 / r1
- print("n2/n1:", s)
- def run():
- print("Welcome to my refraction calculator:)")
- refraction_calculator()
- while True:
- y_or_n = input("\nWould you like to try again?\nYour command(y/n):")
- if y_o
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement