mercredi 7 novembre 2018

Using 'if' variables in Lists

I know this will be very specific and perhaps even asked before but I can't find anything that can help me with it. I'm trying to create a sort of game similar to 'Papers, Please' and am having difficulties using 'if' variables and lists at the same time.

This is my code:

import time
import random

#Variables

NAT = ["British","American","French","Spanish","Italian"]

GEN = ["M","F"]
if GEN == "M":
    FN = ["Greg","Harvey","Joseph","Prabesh","John","Joe"]
elif GEN == "F":
    FN = ["Emma","Olivia","Sophia","Ava","Georgia","Nia"]

LN = ["Sutton","Little","Mayers","Pearce","Fagu","Smith"]
D = list(range(1,28))
M = ["Jan","Feb","March"]
Y = list(range(1900,1975))

#Design

def passport():
    global NAT
    global FN
    global GEN
    print(" __________")
    print("|-PASSPORT-|")
    print("|Nationality:",random.choice(NAT))
    print("|Gender:",random.choice(GEN))
    print("|First Name:",random.choice(FN))
    print("|Last Name:",random.choice(LN))
    print("|D.O.B:",random.choice(D),random.choice(M),random.choice(Y))


passport()

Everything was working fine until I added the gender variable. The error I get is:

Traceback (most recent call last):
  File "C:/Users/Greg/AppData/Local/Programs/Python/Python37-32/Games.py", line 60, in <module>
    passport()
  File "C:/Users/Greg/AppData/Local/Programs/Python/Python37-32/Games.py", line 55, in passport
    print("|First Name:",random.choice(FN))
NameError: name 'FN' is not defined
>>> 

Any help would be much appreciated as I do not know where to go from here. Sorry for being a pain :)

Aucun commentaire:

Enregistrer un commentaire