#๐Ÿ”’ Why Is Save 2 And Save 3 Getting A Error But Not Save 1

98 messages ยท Page 1 of 1 (latest)

full nimbus
#

The Error Happens At Line 195 When It Says if name == 'N/A':

dusky compassBOT
#

@full nimbus

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

full nimbus
#
in_farm = 0 #
cca = 1 #
cp1 = 0
cp2 = 0
cp3 = 0
cp4 = 0
cp5 = 0
pl = 1
plc = 6000 #
dev_mode = 0 #
save_select = 1 #
while save_select == 1:
    save = input("Select Save 1,2,3: ")
    if save == "1":
        s1_name = "s1_name.txt"
        s1_money = "s1_money.txt"
        save_select = 0
    elif save == "2":
        save = "save 2.txt"
        save_select = 0
    elif save == "3":
        save = "save 3.txt"
        save_select = 0
    elif save != "3""2""1":
        print('Please Select Save')

if save == '1':

    with open("s1_money.txt", 'r') as M:
        read1 = M.read()
        read1.strip()
        read1 = int(read1)
        money = read1
        print('\nMoney:',money)

    with open("s1_name.txt", 'r') as N:
        read2 = N.read()
        read2.strip()
        read2 = str(read2)
        name = read2
        print('\nHello:',name)
    
    with open('s1_pl.txt', 'r') as PL:
        read3 = PL.read()
        read3.strip()
        read3 = int(read3)
        pl = read3
    
    with open('s1_c1.txt', 'r') as C1: ```
#
        read4.strip()
        read4 = int(read4)
        cp1 = read4
    
    with open('s1_c2.txt', 'r') as C2:
        read5 = C2.read()
        read5.strip()
        read5 = int(read5)
        cp2 = read5

    with open('s1_c3.txt', 'r') as C3:
        read6 = C3.read()
        read6.strip()
        read6 = int(read6)
        cp3 = read6

    with open('s1_c4.txt', 'r') as C4:
        read7 = C4.read()
        read7.strip()
        read7 = int(read7)
        cp4 = read7

    with open('s1_c5.txt', 'r') as C5:
        read8 = C5.read()
        read8.strip()
        read8 = int(read8)
        cp5 = read8

if save == '2':

    with open("s2_money.txt", 'r') as M1:
        read11 = M1.read()
        read11.strip()
        read11 = int(read11)
        money = read11
        print('\nMoney:',money)

    with open("s2_name.txt", 'r') as N1:
        read21 = N1.read()
        read21.strip()
        read21 = str(read21)
        name = read21
        print('\nHello:',name)
    
    with open('s2_pl.txt', 'r') as PL1:
        read31 = PL1.read()
        read31.strip()
        read31 = int(read31)
        pl = read31 ```
#
        read41 = C11.read()
        read41.strip()
        read41 = int(read41)
        cp1 = read41
    
    with open('s2_c2.txt', 'r') as C21:
        read51 = C21.read()
        read51.strip()
        read51 = int(read51)
        cp2 = read51

    with open('s2_c3.txt', 'r') as C31:
        read61 = C31.read()
        read61.strip()
        read61 = int(read61)
        cp3 = read61

    with open('s2_c4.txt', 'r') as C41:
        read71 = C41.read()
        read71.strip()
        read71 = int(read71)
        cp4 = read71

    with open('s2_c5.txt', 'r') as C51:
        read81 = C51.read()
        read81.strip()
        read81 = int(read81)
        cp5 = read81

if save == '3':

    with open("s3_money.txt", 'r') as M2:
        read12 = M2.read()
        read12.strip()
        read12 = int(read12)
        money = read12
        print('\nMoney:',money)

    with open("s3_name.txt", 'r') as N2:
        read22 = N2.read()
        read22.strip()
        read22 = str(read22)
        name = read22
        print('\nHello:',name)
    
    with open('s3_pl.txt', 'r') as PL2:
        read32 = PL2.read()
        read32.strip() ```
#
        pl = read32
    
    with open('s3_c1.txt', 'r') as C12:
        read42 = C12.read()
        read42.strip()
        read42 = int(read42)
        cp1 = read42
    
    with open('s3_c2.txt', 'r') as C22:
        read52 = C22.read()
        read52.strip()
        read52 = int(read52)
        cp2 = read52

    with open('s3_c3.txt', 'r') as C32:
        read62 = C32.read()
        read62.strip()
        read62 = int(read62)
        cp3 = read62

    with open('s3_c4.txt', 'r') as C42:
        read72 = C42.read()
        read72.strip()
        read72 = int(read72)
        cp4 = read72

    with open('s3_c5.txt', 'r') as C52:
        read82 = C52.read()
        read82.strip()
        read82 = int(read82)
        cp5 = read82

if cp1 == 1:
    cca += 1
if cp2 == 1:
    cca += 1
if cp3 == 1:
    cca += 1
if cp4 == 1:
    cca += 1
if cp5 == 1:
    cca += 1

if name == "N/A":
wise harbor
#

theres an indentation issue and a logical error in the condition to handle the save selection

full nimbus
#

?

#

lemme see if i can show the whole source

dusky compassBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

visual stratus
#

Also tell what your input is and what output you're getting

full nimbus
#

okay

#

so when its starts up it asks for save 1 2 or 3

#

i pick 1 it works

#

if i pick 2 or 3 i get this error:

#

Traceback (most recent call last):
File "c:\Users\minec\Desktop\PyFarm\PyFarm.py", line 195, in <module>
if name == "N/A":
^^^^
NameError: name 'name' is not defined. Did you mean: 'game'?
PS C:\Users\minec\Desktop\PyFarm>

visual stratus
#

Also, did you write this code?

full nimbus
#

yes

full nimbus
#

it was too big i think

visual stratus
full nimbus
#

mk

#

i dont have discord nitro and cant send msges over 500 characters

#

oh nvm

#

i see the link

#

do you need to see whats in the storage files

visual stratus
# full nimbus https://paste.pythondiscord.com/3XOQ

After this block of code:

while save_select == 1:
    save = input("Select Save 1,2,3: ")
    if save == "1":
        s1_name = "s1_name.txt"
        s1_money = "s1_money.txt"
        save_select = 0
    elif save == "2":
        save = "save 2.txt"
        save_select = 0
    elif save == "3":
        save = "save 3.txt"
        save_select = 0
    elif save != "3""2""1":
        print('Please Select Save')

What values can the save variable have?

full nimbus
#

on sec

#

OHHHHHHH

#

my bad i dont have the other ones set up yet i think

visual stratus
full nimbus
#

mabye

#

hold up im confused now

#

save can have int float and str

#

right?

visual stratus
#

Suppose you have this:

color = input("Enter color: ")
if color == "red":
    color = "pink"
elif color == "green":
    color = "yellow"
elif color == "purple":
    print("my favourite color")
else:
    color = "unknown"

print(color)

What are all the possible outputs of the bottom print?

full nimbus
#

umm leme think

#

a ton

#

like litterly anything i type for example: '2hydf'

visual stratus
#

What will the output be if you type 2hydf?

full nimbus
#

2hydf???

#

OGHHHH

#

Unknown

#

im really tierd i promise

visual stratus
#

right

#

Can it ever output red?

full nimbus
#

no

#

cheating

visual stratus
#

Using ChatGPT is not necessarily cheating, but it will confidently give you absolutely wrong answers

full nimbus
visual stratus
#

Yeah that should be replaced with else: but it shouldn't matter for the question

full nimbus
#

yeah i did that and nothing changed witch is expected

#

so what am i doing wrong?

visual stratus
#

what can possibly be in the save variable after the loop?

full nimbus
#

1 2 or 3?

visual stratus
#

What input should you enter so that the save variable stores "2" after the loop?

pine bear
#

Each save is ment to preform the same task right? Like save input

visual stratus
#
    elif save == "2":
        save = "save 2.txt"
        save_select = 0
full nimbus
#

oh

#

how did i miss this?

#

wait were is that located

visual stratus
#

at the very top

#

You will miss all sorts of stuff when you're tired ๐Ÿ™‚ or when you've been looking at the same code for many hours

full nimbus
visual stratus
#

Lines 13 to 26 in your file

full nimbus
#

mhm

#

oh now i see

#

lol

#

well thx so much

#

im prett new like mabye 2 days worth of knowlage

#

so thx for the help

visual stratus
#

If you're stuck at something, try to trace back your steps

full nimbus
#

yea thats a good idea

visual stratus
full nimbus
#

i was thinking in 1 dimension

#

no deeper

visual stratus
#

Also, I strongly recommend giving more meaningful names to variables. cp3 and cca are very mysterious and don't convey their meaning

full nimbus
#

cca means crop cost amount cp3 means crop purchance 3

#

but yea

#

i should make them easyier to read

#

thanks again

#

!close

dusky compassBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.