Advertisement
Guest User

sajidPython

a guest
Nov 11th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.03 KB | None | 0 0
  1. import math
  2. from math import sin
  3. from math import pi as n
  4.  
  5. print(" Welcome to Refraction Calculator!       ")
  6. print("    Created by:Sajid Ul Islam    ")
  7. print("   ===========================================       ")
  8.  
  9.  
  10. def refraction_calculator():
  11.     print('What do you want to find?)')
  12.     print("1.Snel's law\n2.Relative refraction")
  13.     user_input1 = input('Your answer:')
  14.     if user_input1 == '1':
  15.         print('What do you want to find?')
  16.         print('1.Sin1\n2.Sin2\n3.n1\n4.n2')
  17.         user_input = input('Your answer:')
  18.  
  19.         if user_input == "1":
  20.             Sin2 = float(input('Enter the value of Sin2:')) * n / 180
  21.             b = math.sin(Sin2)
  22.             n1 = float(input('Enter the value of n1:'))
  23.             n2 = float(input('Enter the value of n2:'))
  24.             Result = ((b / n2) * n1)
  25.             print("Sin1:", Result)
  26.  
  27.         elif user_input == "2":
  28.             Sin1 = float(input('Enter the value of Sin1:')) * n / 180
  29.             b = math.sin(Sin1)
  30.             n1 = float(input('Enter the value of n1:'))
  31.             n2 = float(input('Enter the value of n2:'))
  32.             Result = ((b * n1) / n2)
  33.             print('Sin2:', Result)
  34.  
  35.  
  36.         elif user_input == '3':
  37.             Sin1 = float(input('Enter the value of Sin1:')) * n / 180
  38.             b = math.sin(Sin1)
  39.             Sin2 = float(input('Enter the value of Sin2:')) * n / 180
  40.             c = math.sin(Sin2)
  41.             n2 = float(input('Enter the value of n2:'))
  42.             Result = ((c * n2) / b)
  43.             print('n1:', Result)
  44.  
  45.         elif user_input == '4':
  46.             Sin1 = float(input('Enter the value of Sin1:')) * n / 180
  47.             b = math.sin(Sin1)
  48.             Sin2 = float(input('Enter the value of Sin2:')) * n / 180
  49.             c = math.sin(Sin2)
  50.             n1 = float(input('Enter the value of n1:'))
  51.             Result = ((b * n1) / c)
  52.             print('n2:', Result)
  53.  
  54.     if user_input1 == '2':
  55.         print('Which relative refraction do you want to find?')
  56.  
  57.         print('1.n1/n2 \n2.n2/n1')
  58.         user_input = input('Your answer:')
  59.  
  60.         list2 = [1.00, 1.00029, 1.33, 1.52, 2.42]
  61.  
  62.         if user_input == '1':
  63.             print('1.Zero\n2.Air\n3.Water\n4.Glass\n5.Diamond')
  64.             n1 = str(input('Enter the number of the name of n1:'))
  65.  
  66.             if n1 == '1':
  67.                 r1 = list2[0]
  68.                 print("Refraction value:", r1)
  69.  
  70.             elif n1 == '2':
  71.                 r1 = list2[1]
  72.                 print("Refraction value:", r1)
  73.             elif n1 == '3':
  74.                 r1 = list2[2]
  75.                 print("Refraction value:", r1)
  76.             elif n1 == '4':
  77.                 r1 = list2[3]
  78.                 print("Refraction value:", r1)
  79.             elif n1 == '5':
  80.                 r1 = list2[4]
  81.                 print("Refraction value:", r1)
  82.  
  83.             n2 = str(input('Enter the number of the name of n2:'))
  84.             if n2 == '1':
  85.                 r2 = list2[0]
  86.                 print('Reflection value:', r2)
  87.  
  88.             if n2 == '2':
  89.                 r2 = list2[1]
  90.                 print("Refraction value:", r2)
  91.             elif n2 == '3':
  92.                 r2 = list2[2]
  93.                 print("Refraction value:", r2)
  94.             elif n2 == '4':
  95.                 r2 = list2[3]
  96.                 print("Refraction value:", r2)
  97.             elif n2 == '5':
  98.                 r2 = list2[4]
  99.                 print("Refraction value:", r2)
  100.  
  101.             s = r1 / r2
  102.             print('n1/n2:', s)
  103.  
  104.         if user_input == '2':
  105.             print('1.Zero\n2.Air\n3.Water\n4.Glass\n5.Diamond')
  106.  
  107.             n1 = str(input('Enter the number of the name of n1:'))
  108.  
  109.             if n1 == '1':
  110.                 r1 = list2[0]
  111.                 print("Refraction value:", r1)
  112.  
  113.             elif n1 == '2':
  114.                 r1 = list2[1]
  115.                 print("Refraction value:", r1)
  116.             elif n1 == '3':
  117.                 r1 = list2[2]
  118.                 print("Refraction value:", r1)
  119.             elif n1 == '4':
  120.                 r1 = list2[3]
  121.                 print("Refraction value:", r1)
  122.             elif n1 == '5':
  123.                 r1 = list2[4]
  124.                 print("Refraction value:", r1)
  125.  
  126.             n2 = str(input('Enter the number of the name of n2:'))
  127.             if n2 == '1':
  128.                 r2 = list2[0]
  129.                 print('Reflection value:', r2)
  130.  
  131.             if n2 == '2':
  132.                 r2 = list2[1]
  133.                 print("Refraction value:", r2)
  134.             elif n2 == '3':
  135.                 r2 = list2[2]
  136.                 print("Refraction value:", r2)
  137.             elif n2 == '4':
  138.                 r2 = list2[3]
  139.                 print("Refraction value:", r2)
  140.             elif n2 == '5':
  141.                 r2 = list2[4]
  142.                 print("Refraction value:", r2)
  143.             s = r2 / r1
  144.             print("n2/n1:", s)
  145.  
  146.  
  147. def run():
  148.     print("Welcome to my refraction calculator:)")
  149.     refraction_calculator()
  150.     while True:
  151.         y_or_n = input("\nWould you like to try again?\nYour command(y/n):")
  152.         if y_o
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement