Python Forum
Need to use range with decimals
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need to use range with decimals
#7
Here is the entire program:
import math

h = float(input("What is the value of H0 (in km/s/Mpc)?"))
j = float(input("what is the value of the matter density parameter?"))
cs = input("Do you want a flat or open cosmology (1 = flat, 0 = open)?")
ran = input("Do you want a range of readshifts (min, max, increment), or a list (type range, list, o$


if ran == "range":
    i = float(input("What is the minimum z value?"))
    k = float(input("What is the maximum z value?"))
    u = float(input("By what increment?"))
    z = i
    data = [z]
    while i < k:
        data.append(i)
        z += u

def eta(a, omega):
    s = ((1- omega)/omega)**(1/3)
    return 2*math.sqrt(s**3 + 1)*(1/(a**4) - 0.01540*s/(a**3) + 0.4304*(s**2)/(a**2)\
                                  + 0.19097*(s**3)/a +0.066942*s**4)**(-1/8)
c = 3e8
q = (j/2)

d1 = (1/(1 + z))*(c/h)*(eta(1, j) - eta(1/(1 +z), j))
d1 = d1*(math.pi/180)*(1/3600)

d2 = (c/(h*q**2))*(((z*q) +(q - 1)*(math.sqrt(2*z*q + 1) - 1))/((1 + z)**2))
d2 = d2*(math.pi/180)*(1/3600)

if cs == "1":
    print(d1)
else:
    print(d2)
Reply


Messages In This Thread
Need to use range with decimals - by KameronG - Feb-08-2019, 03:15 PM
RE: Need to use range with decimals - by Larz60+ - Feb-08-2019, 04:01 PM
RE: Need to use range with decimals - by ichabod801 - Feb-08-2019, 04:07 PM
RE: Need to use range with decimals - by woooee - Feb-08-2019, 07:14 PM
RE: Need to use range with decimals - by KameronG - Feb-08-2019, 07:31 PM
RE: Need to use range with decimals - by ichabod801 - Feb-08-2019, 07:47 PM
RE: Need to use range with decimals - by KameronG - Feb-08-2019, 07:49 PM
RE: Need to use range with decimals - by ichabod801 - Feb-08-2019, 07:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Limiting Decimals FZMoto 2 3,157 Jul-01-2017, 03:36 AM
Last Post: FZMoto

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020