Feb-08-2019, 03:15 PM
Hello,
I need to write a program that asks for values from a user and then use the values in a formula. One thing I need to do is ask the user if they want a range, list, or single value for one of the parameters, but I can't figure out how to do this. I don't think I'm allowed to use numpy for this. Here is my code:
There's more after that, but I don't want to post my entire code for this issue unless I have to.
So, the range gives me SOMETHING if I give it only integers, but it only gives me one value and I don't know why. For example, if I use (1, 3, 1), it only gives one value instead of 3. Beyond this, using integers only makes the range pointless as redshifts aren't often integers.If anyone knows a way this can be done, I greatly appreciate it. Thank you.
I need to write a program that asks for values from a user and then use the values in a formula. One thing I need to do is ask the user if they want a range, list, or single value for one of the parameters, but I can't figure out how to do this. I don't think I'm allowed to use numpy for this. Here is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import math h = float ( input ( "What is the value of H0 (in km/s/Mpc)?" )) z = float ( input ( "What is the value of the redshift?" ) 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 of the range you desire (enter min z value)?" )) k = float ( input ( "What is the maximum of the range you desire (enter max z value)?" )) u = float ( input ( "By what increment do you want z to be calculated (enter increment size)?" )) for z in range (i, k, u): z = z + u |
So, the range gives me SOMETHING if I give it only integers, but it only gives me one value and I don't know why. For example, if I use (1, 3, 1), it only gives one value instead of 3. Beyond this, using integers only makes the range pointless as redshifts aren't often integers.If anyone knows a way this can be done, I greatly appreciate it. Thank you.