dimanche 27 mai 2018

Variables not passing though if statements?

Look I honestly don't know where my code is going wrong here so I've posted the whole thing. I have made this programme to generate random weather conditions for over land travel in my game of dungeons and dragons. I have tried to generate different weather patterns by making a variable thats value is between 1 and 20 and then comparing it against a range to find out what that days weather was like. The code is as follows:

import random

def day():
    temp = random.randint(1,20)
    wind = random.randint(1,20)
    percip = random.randint(1,20)
    isweird = random.randint(1,20)
    encounter = random.randint(1,12)

    #Temperature block
    if 1 <= temp <= 14:
        daystemp = ("Normal for the season")
    elif 15 <= temp <= 17:
        d4 = (random.randint(1,4))*5
        daystemp = (d4, 'degrees hotter than normal')
    elif 18 <= temp <= 20:
        d4 = (random.randint(1,4))*5
        daystemp = (d4, 'degrees colder than normal')
    else:
        temp = "Process not completed"

    #Wind block
    if 1 <= wind <= 12:
        daystemp = ("None")
    elif 13 <= wind <= 17:
        daystemp = ("Light")
    elif 18 <= wind <= 20:
        daystemp = ("Strong")

    #Precipitation block
    if 1 <= wind <= 12:
        daystemp = ("None")
    elif 13 <= wind <= 17:
        daystemp = ("Light rain or light snowfall")
    elif 18 <= wind <= 20:
        daystemp = ("Heavy rain or heavy snowfall")

    #isweird? Block
    weird = [
    'Dead magic zone (similar to an antimagicfield)',
    'Dead magic zone (similar to an antimagicfield)',
    'Wild magic zone (roll on the Wild Magic Surge table in the Players Handbook whenever a spell is cast with in the zone)',
    'Boulder carved with talking faces','Crystal cave that mystically answers questions',
    'Ancient tree containing a trapped spirit',
    'Battlefield where lingering fog occasionally assumes humanoid forms',
    'Battlefield where lingering fog occasionally assumes humanoid forms',
    'Battlefield where lingering fog occasionally assumes humanoid forms',
    'Wishingwell','Giant crystal shard protruding from the ground',
    'Wrecked ship, which might be nowhere near water',
    'Haunted hill or barrow mound',
    'Field of petrified soldiers or other creatures',
    'Floating earth mote with a tower on it'
    ]
    if 1 <= isweird <= 2:
        isweird = random.choice(weird)
    else:
        isweird = ("No weird locale")

    #Return block
    print(temp)
    print(wind)
    print(percip)
    print(isweird)


days = int(input("How many Days: "))
daybuffer = 0
daterecord = 0

while daybuffer < days:
    daybuffer += 1
    daterecord += 1
    print('\nIt is day ', daterecord)
    print(day())

This code ends up returning (for 1 day or any days)

 It is day  1
 13
 1
 11
 Floating earth mote with a tower on it
 None

So 3 problems:

  1. The Temperature wind and precipitation just shows an integer
  2. The weird locale does work for some reason even though its code is similar
  3. There is a mystery 5th item that just reads None(???)

What the heck is going on?




Aucun commentaire:

Enregistrer un commentaire