#๐ Why Is Save 2 And Save 3 Getting A Error But Not Save 1
98 messages ยท Page 1 of 1 (latest)
@full nimbus
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.
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":
theres an indentation issue and a logical error in the condition to handle the save selection
!paste
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.
Also tell what your input is and what output you're getting
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>
Can you post the whole code as text?
Also, did you write this code?
yes
Read this embed
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
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?

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?
What will the output be if you type 2hydf?
Okay, now assuming that elif save != "3""2""1" is replaced with else (the original line doesn't really work but it's not important here), what can possibly be in the save variable after the loop?
Using ChatGPT is not necessarily cheating, but it will confidently give you absolutely wrong answers
lemme see so i should just remove that part?
Yeah that should be replaced with else: but it shouldn't matter for the question
what can possibly be in the
savevariable after the loop?
1 2 or 3?
What input should you enter so that the save variable stores "2" after the loop?
Each save is ment to preform the same task right? Like save input
umm im not sure here
a 2?
elif save == "2":
save = "save 2.txt"
save_select = 0
^
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
yea true
at teh top of that block
Lines 13 to 26 in your file
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
If you're stuck at something, try to trace back your steps
yea thats a good idea
When you see this error, it must mean that the name variable wasn't defined.
Where is the name variable defined? Under one of the if save == "1", if save == "2", if save == "3" blocks. So if it's not defined, it means that save is neither "1", "2", nor "3".
Where is save defined? ...and so on
oh i see
i was thinking in 1 dimension
no deeper
Also, I strongly recommend giving more meaningful names to variables. cp3 and cca are very mysterious and don't convey their meaning
cca means crop cost amount cp3 means crop purchance 3
but yea
i should make them easyier to read
thanks again
!close
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.