I'm trying to make a code that:
- takes in user input for xyz coordinate on planet earth
- takes in how many teleportation stations they need to get to another planet
- takes in user input for xyz coordinate for each teleportation station
I'm struggling to:
- make a code that only accepts and prints the user input to 2 decimal places-let's say one of my coordinates were >>1 2.23 2.235, the output only seems to give 2.23 instead of 2.24.
- ensure that the coordinates are between -10000 and 10000 and that the number of teleportation stations are only between 1 and 2000
- make the code re-prompt the user input if the input is out of range
- only enter 3 values in each input
The more I try to fix it, the more I get confused and longer the code gets.
This is my code so far:
def earth_coordinates(): earthCo = (map(float, input("Please enter your coordinates on Earth: ").split())) for index in earthCo: if index < -10000.00 or index > 10000.00: print("Out of range, try again") earth_coordinates() else: number_of_TPS() break def number_of_TPS(): N = int(input("Enter how many teleportation stations: ")) if N not in range(1,2000): print('Coordinate values are out of range, they must be within 1 and 2000') number_of_TPS() else: #break for x in range(0, N): stationCo = (map(float, input("Enter station coordinate: ").split())) stationCo2d = [round(elem, 3) for elem in stationCo] #for float(coordinate) in stationCo: #if coordinate < -10000.00 or x > 10000.00: listofallinput.extend(stationCo2d) listofallinput.sort() print(listofallinput) #else: #print("Out of range, try again") #number_of_TPS() earth_coordinates()
https://stackoverflow.com/questions/65820237/how-to-round-up-items-in-a-list-to-two-decimal-places-and-prompt-user-the-same-q January 21, 2021 at 10:07AM
没有评论:
发表评论