Я только начал изучать python, используя учебники на веб-сайте. Одна лаборатория заставила меня создать эту игру верблюда, которая, как я знаю, по-прежнему неполна. Прямо сейчас я пытаюсь понять, как печатать мили, за которыми стоят аборигены, без того, чтобы число было отрицательным (так как это не имеет смысла). Я знаю, что в коде есть другие ошибки, но сейчас я сосредоточен на этой проблеме.Python camel game problem
Заранее благодарен! Вот код:
import random
print("Welcome to Camel!")
print("You have stolen a camel to make your way across the great Mobi desert.")
print("The natives want their camel back and are chasing you down! Survive your \n"
"desert trek and out run the natives.")
print()
done = False
# VARIABLES
miles_traveled = 0
thirst = 0
tiredness = 0
natives_travel = -20
canteen = 5
forward_natives = random.randrange(0, 10)
full_speed = random.randrange(10, 20)
moderate_speed = random.randrange(5, 12)
oasis = random.randrange(0, 21)
# MAIN PROGRAM LOOP
while not done:
print("A. Drink from your canteen.")
print("B. Ahead moderate speed.")
print("C. Ahead full speed.")
print("D. Stop for the night.")
print("E. Status check.")
print("Q. Quit.")
choice = input("Your choice? ")
print()
if choice.upper() == "Q":
done = True
print("You quit!")
# STATUS CHECK
elif choice.upper() == "E":
print("Miles traveled: ", miles_traveled)
print("Drinks in canteen: ", canteen)
print("The natives are", (natives_travel + 20), "miles behind you.")
print()
# STOP FOR THE NIGHT
elif choice.upper() == "D":
tiredness = 0
print("The camel is happy")
natives_travel = natives_travel + forward_natives
print("The natives are", natives_travel, "miles behind you.")
print()
# FULL SPEED AHEAD
elif choice.upper() == "C":
if oasis == 1:
print("Wow you found an oasis")
canteen = 5
thirst = 0
tiredness = 0
else:
miles_traveled = miles_traveled + full_speed
print("You walked", full_speed, "miles.")
thirst += 1
tiredness = tiredness + random.randrange(1, 4)
natives_travel = natives_travel + forward_natives
print(forward_natives)
print("The natives are", natives_travel, "miles behind you.")
print()
# MODERATE SPEED
elif choice.upper() == "B":
if oasis == 1:
print("Wow you found an oasis")
canteen = 5
thirst = 0
tiredness = 0
else:
miles_traveled = miles_traveled + moderate_speed
print("You walked", moderate_speed, "miles")
thirst += 1
tiredness = tiredness + random.randrange(1, 3)
natives_travel = natives_travel + forward_natives
print("The natives are", natives_travel, "miles behind you.")
print()
# DRINK FROM CANTEEN
elif choice.upper() == "A":
if canteen >= 1:
canteen -= 1
thirst = 0
if canteen == 0:
print("You have no drinks in the canteen!")
print()
if miles_traveled >= 200:
print("You have won!")
done = True
if not done and thirst >= 6:
print("You died of thirst!")
done = True
print()
if not done and thirst >= 4:
print("You are thirsty.")
print()
if not done and tiredness >= 8:
print("Your camel is dead")
done = True
print()
if not done and tiredness >= 5:
print("Your camel is getting tired.")
print()
if natives_travel >= miles_traveled:
print("The natives have caught you!")
done = True
print()
elif natives_travel <= 15:
print("The natives are getting close!")
print()
Туземцы находятся в двадцати милях отсюда? 'print (-natives_travel)' или 'print (abs (natives_travel))' – miradulo
Возможный дубликат [Как преобразовать отрицательное число в положительное?] (http://stackoverflow.com/questions/3854310/how-to- конвертировать-а-отрицательный-номер-в-положительных) – miradulo