473,809 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help fixing if/while statement

2 New Member
Hi Im currently building a script game, soon to be image game. Having trouble with a part of a code.
Expand|Select|Wrap|Line Numbers
  1. ranger_join = raw_input("\nWill you let him?(y/n)? ")
  2.  
  3. if ranger_join == "y":
  4.     print "The ranger joins you on your trip.  Yay."
  5.  
  6. elif ranger_join == "n":
  7.     print "The ranger is offended and draws his sword.\n"
  8.     # attacking the ranger
  9.     weapon = raw_input("What weapon do you have? Oak Staff or Iron Sword? ")
  10.     #using the Oak Staff
  11.     if weapon == "oak staff":
  12.         attack = 3
  13.         print "\nYou draw your Oak Staff"
  14.         attack = 3
  15.         while ranger_health > 0:
  16.             ranger_health = ranger_health - attack
  17.             health = health - ranger_damage
  18.  
  19.             print "You're hero takes a swing and the ranger has", ranger_health, " health remaining."\
  20.                   "But you have", health, "hit points remaining\n"
  21.             if health <= 0:
  22.                 print "You died.  Bet you wish you stayed at the inn."
  23.  
  24.     # using the Iron Sword
  25.     elif weapon == "iron sword":
  26.         print "\nYou draw your Iron Sword"
  27.         attack = 5
  28.         while ranger_health > 0 or health > 0:
  29.             ranger_health = ranger_health - attack
  30.             health = health - ranger_damage
  31.  
  32.             print "You're hero takes a swing and the ranger has", ranger_health, " health remaining."\
  33.                   "But you have", health, "hit points remaining\n"
  34.             if ranger_health <= 0:
  35.                 print "It sucks"
  36.                 exit
  37.             #gain an item for defeating ranger
  38.  
  39.             elif health <= 0:
  40.                 print "You died.  Bet you wish you stayed at the inn.\n"
  41.  
This is for a fantasy type game. When the hero has been killed, the code keeps running until the ranger dies. How do I fix this up?

But later on I will be trying to create a function for turns at attacking.
Oct 19 '07 #1
2 1346
diegososa
19 New Member
Please post the code with [code ] and [/ code] to keep indentation !
Oct 19 '07 #2
KaezarRex
52 New Member
Hi Im currently building a script game, soon to be image game. Having trouble with a part of a code.

Expand|Select|Wrap|Line Numbers
  1. ranger_join = raw_input("\nWill you let him?(y/n)? ")
  2.  
  3. if ranger_join == "y":
  4.     print "The ranger joins you on your trip.  Yay."
  5.  
  6. elif ranger_join == "n":
  7.     print "The ranger is offended and draws his sword.\n"
  8.     # attacking the ranger
  9.     weapon = raw_input("What weapon do you have? Oak Staff or Iron Sword? ")
  10.     #using the Oak Staff
  11.     if weapon == "oak staff":
  12.         attack = 3
  13.         print "\nYou draw your Oak Staff"
  14.         attack = 3
  15.         while ranger_health > 0:
  16.             ranger_health = ranger_health - attack
  17.             health = health - ranger_damage
  18.  
  19.             print "You're hero takes a swing and the ranger has", ranger_health, " health remaining."\
  20.                   "But you have", health, "hit points remaining\n"
  21.             if health <= 0:
  22.                 print "You died.  Bet you wish you stayed at the inn."
  23.  
  24.     # using the Iron Sword
  25.     elif weapon == "iron sword":
  26.         print "\nYou draw your Iron Sword"
  27.         attack = 5
  28.         while ranger_health > 0 or health > 0:
  29.             ranger_health = ranger_health - attack
  30.             health = health - ranger_damage
  31.  
  32.             print "You're hero takes a swing and the ranger has", ranger_health, " health remaining."\
  33.                   "But you have", health, "hit points remaining\n"
  34.             if ranger_health <= 0:
  35.                 print "It sucks"
  36.                 exit
  37.             #gain an item for defeating ranger
  38.  
  39.             elif health <= 0:
  40.                 print "You died.  Bet you wish you stayed at the inn.\n"
This is for a fantasy type game. When the hero has been killed, the code keeps running until the ranger dies. How do I fix this up?

But later on I will be trying to create a function for turns at attacking.
To exit the while loop, when your hero dies, use "break"

Expand|Select|Wrap|Line Numbers
  1. if health <= 0:
  2.     print "You died.  Bet you wish you stayed at the inn."
  3.     break #used to immediately exit any for or while loop
Oct 19 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
1947
by: Steven D'Aprano | last post by:
I've been working with the Borg design pattern from here: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531 and I'm having problems subclassing it. I'm a newbie, so I've probably missed something obvious. I want two Borg-like classes where all instances share state within each class, but not between them. This is what I tried:
5
3535
by: imranzafar | last post by:
Hi! I am a beginner in C++. This is little assignment. It gives an error "Structure Require on Left Side of dot operator" Can anybody help me what went wrong in this code? #include <conio.h> #include <stdio.h> #include <iostream.h> void set(void); void display(void);
6
1457
by: Marlene Stebbins | last post by:
My hobby project is a library of routines in C that do big integer arithmetic. I've been working on it for several weeks and it now consists of about 1200 lines of code. I've got addition, subraction and multiplication working, but there is a problem with division. I think my algorithm is OK; it's nothing fancy, just grade school long division. It crashes with a seg fault on some inputs and produces the correct result with others. Despite...
3
1582
by: luna | last post by:
theres no errors in my code - but it does nothing at all - its supposed to be populating text boxes!! any ideas ? (im am pretty new to all this) If Not Page.IsPostBack Then Dim search As String Dim strConn As String = "server=Gringotts;uid=sa;pwd=password;database=database"
27
1985
by: sam_cit | last post by:
Hi, I needed help in converting a character to the correspoding hexadecimal values, like the following example, ASCII value : ABC Hex Code Value : %41%42%43... whats the logic of conversion...
7
2189
by: Buck Rogers | last post by:
Hi all! Newbie here. Below is an example from Teach Yourself C in 21 Days. My apologies if it is a bit long. What I don't understand is how the "get_data" function can call the "continue_function", and if NO is returned to "get_data", display_report executes and the program ends? Basically I am having trouble understanding the program flow within the "if" loop in the "main" function.
1
2827
by: Randy Volkart | last post by:
I'm trying to fix a glitch in a complex access database, and have a fairly complex problem... unless there's some obscure easy fix I don't know being fairly new with Access. Basically, the area I'm trying to fix includes a form which takes entered data, concatenates it into a VB string to form an SQL query, then launches a report with information from the query. Several tables are linked in the query, but the key ones for this problem...
2
8172
by: kya2 | last post by:
I am not able to create following store procedure. CREATE PROCEDURE DBSAMBA.InsertDeleteBatch(OUT norows INT ) RESULT SETS 1 LANGUAGE SQL BEGIN part1 DECLARE TOTAL_LEFT INT DEFAULT 0; SELECT COUNT(*)INTO TOTAL_LEFT FROM DBSAMBA.REPORTEDTRANSACTION_S; WHILE (TOTAL_LEFT > 0) DO
26
2357
by: Ravindra.B | last post by:
I have declared a global variable which is array of pointers and allocated memory for each array variable by using malloc. Some thing similar to below... static char *arr; main() { int i;
0
9603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10640
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10120
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7662
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.