-1

I just started learning python using tutorials on a website. One lab had me create this camel game which I know is still incomplete. Right now I am trying to figure out how to print the miles the natives are behind without the number being negative (since this makes no sense). I know there are probably other errors in the code but right now I am focusing on this problem.

Thanks in advance! Here is the code:

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()
miradulo
  • 28,857
  • 6
  • 80
  • 93
  • The natives are twenty miles behind? `print(-natives_travel)`, or `print(abs(natives_travel))` – miradulo Mar 24 '15 at 16:46
  • possible duplicate of [How to convert a negative number to positive?](http://stackoverflow.com/questions/3854310/how-to-convert-a-negative-number-to-positive) – miradulo Mar 24 '15 at 17:02

1 Answers1

0

Use the function abs() for absolute value. Or, if this distance is always negative, just... use a minus sign?

Godzy
  • 157
  • 1
  • 10