-
def load(): # function to load game data
-
if os.path.exists('./data.dat') == True:
-
load = open('data.dat', 'r')
-
save = load.readline()
-
if save == "":
-
welcome()
-
elif save == "1\n" or "1":
-
chce = raw_input("A saved game has been detected. Would you like to load this? Y/N ")
-
if chce == "Y" or "y":
-
pass # Not came that far yet
-
elif chce == "N" or "n":
-
welcome()
-
else:
-
print "Invalid choice please choose Y for yes or N for no."
-
else:
-
print "Fatal Error: 'data.dat' not detected."
-
This is an excerpt of a text-based RPG I am currently writing. The problem is when I come to line 8 where it asks if I want to load a saved game or not. For some reason I just can't understand it doesn't do what its supposed to do. One: it doesn't give me the "else" section if I type in something other than Y, y, N, n. Two: it doesn't go to my "welcome()" function if I select N or n. I get no errors. The program will just exit when I try one of those things :S
Am I missing something obvious? Perhaps a syntax issue - like a block of code not in the right place. I am not that new to Python and have made a text-based RPG before in this language. However its been a while since I started using it again so maybe I am having a noob moment. Any help would be greatly appreciated, thanks,
6 1481 bvdet 2,851
Expert Mod 2GB -
def load(): # function to load game data
-
if os.path.exists('./data.dat') == True:
-
load = open('data.dat', 'r')
-
save = load.readline()
-
if save == "":
-
welcome()
-
elif save == "1\n" or "1":
-
chce = raw_input("A saved game has been detected. Would you like to load this? Y/N ")
-
if chce == "Y" or "y":
-
pass # Not came that far yet
-
elif chce == "N" or "n":
-
welcome()
-
else:
-
print "Invalid choice please choose Y for yes or N for no."
-
else:
-
print "Fatal Error: 'data.dat' not detected."
-
This is an excerpt of a text-based RPG I am currently writing. The problem is when I come to line 8 where it asks if I want to load a saved game or not. For some reason I just can't understand it doesn't do what its supposed to do. One: it doesn't give me the "else" section if I type in something other than Y, y, N, n. Two: it doesn't go to my "welcome()" function if I select N or n. I get no errors. The program will just exit when I try one of those things :S
Am I missing something obvious? Perhaps a syntax issue - like a block of code not in the right place. I am not that new to Python and have made a text-based RPG before in this language. However its been a while since I started using it again so maybe I am having a noob moment. Any help would be greatly appreciated, thanks,
Your problem is here:
It should be: - if chce == "Y" or chce == "y"
This looks better:
>>> s = 'N'
>>> s == 'y' or 'Y'
'Y'
>>> if s == 'y' or 'Y':
... print "'Y' evaluates True"
...
'Y' evaluates True
>>>
Your problem is here:
It should be: - if chce == "Y" or chce == "y"
This looks better:
>>> s = 'N'
>>> s == 'y' or 'Y'
'Y'
>>> if s == 'y' or 'Y':
... print "'Y' evaluates True"
...
'Y' evaluates True
>>>
Silly me, it really was a noob moment. I mean really, what language in earth is smart enough to take 'or' as direct as that. OK back to work!
Thank you for your help bvdet :)
Silly me, it really was a noob moment. I mean really, what language in earth is smart enough to take 'or' as direct as that. OK back to work!
Thank you for your help bvdet :)
I often use the in operator in order to shorten many combined ors: - if chce in "Yy":
-
print 'yep'
Thats great. My code looks a lot neater now. Thanks for sharing that bartonc.
Thats great. My code looks a lot neater now. Thanks for sharing that bartonc.
Any time, really. And you may call me "Barton".
Thanks for joining us here on the Python Forum at TSDN!
Any time, really. And you may call me "Barton".
Thanks for joining us here on the Python Forum at TSDN!
Thank you for welcoming me Barton! This is a great forum =)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Bruno van Dooren |
last post by:
Hi All,
i have some (3) different weird pointer problems that have me stumped. i
suspect that the compiler behavior is correct because gcc shows the same
results.
...
|
by: tborn |
last post by:
Hi there,
Not sure if any one has experienced this before and can tell me what's
wrong with this statement:
if verified = false then dataObjects.HasError = true
This is all on one line...
|
by: Praveen_db2 |
last post by:
Hi All
db2 8.1.3 Windows
I have folowing table structures
CREATE TABLE tb_RTB(
EMP_ID INTEGER,
DESC VARCHAR(20));
CREATE TABLE tb_ERROR(
SQL_STATE CHAR(5),
SQL_DESC VARCHAR(20),
|
by: Dox33 |
last post by:
I ran into a very strange behaviour of raw_input().
I hope somebody can tell me how to fix this.
(Or is this a problem in the python source?)
I will explain the problem by using 3 examples....
|
by: ananthaisin |
last post by:
How to reduce the table size for any table while using truncate or delete statements. In oracle 8i it was truncating the storage space but in 10g it is not ....
I have given truncate statement in...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |