I am trying to make a python script that will prompt the user for two input floats and perform calculations with the input. Before I can get to that part I am having trouble understanding how to create an object and access it.
I am starting out simple with just one object here called FightingForce to learn the concept I am just take input for creating 1 of these object and trying to print it.
My question is how do I get the user input and store it as a FightingForce object, that is accessible for use in an equation?
# Create a fighting force object
class FightingForce(object):
size = 0
lethalityCoefficient = 0
# Class constructor/initilizer
def __init__(self, size, lethalityCoefficient):
self.size = size
self.lethalityCoefficient = lethalityCoefficient
def make_fightingForce(size, lethalityCoefficient):
fightingForce = FightingForce(size, lethalityCoefficient)
return fightingForce
# Prevent user from inputting anything other than a float
while True:
try:
# Promt user for input and set variables
size = float(raw_input('Enter the amount of troops: '))
lethalityCoefficient = float(raw_input('Enter the lethality coefficient: '))
except ValueError:
print("Please input a floating point integer greater than zero")
continue
else:
break
# Display results to user
print(fightingForce.size)
raw_input('Press <ENTER> to exit')
Currently my code will ask for the two inputs and immediately close after I enter them. I have tried placing "raw_input('Press to exit')" in various locations in an attempt to see where it is failing but I am not getting any good results.