Python Forum
No option to input - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: No option to input (/thread-2451.html)



No option to input - Sp00f - Mar-17-2017

[Image: Sw4cJfq.png]

Hello, I'm running this with no error. But it isn't giving an option to input.

Can someone explain to me why it's not launching the text field? Thank you


RE: No option to input - buran - Mar-17-2017

don't post images. post code in code tags.
all this code does is to call def main that in turn define class player1 with two methods. you never create an instance(s) of the class and use it(them)
in addition - once you resolve this, it will give some errors with the properties of the class


RE: No option to input - Sp00f - Mar-17-2017

can someone try and show me? here it is

def main():

  class player1:
    stay = True
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def getAge(self, age):
        self.age = age

    def getName(self, name):
         self.name = name

         name.player1 = input('What is your name? ')
         age.player1 = input('How old are you? ')
         print("Cool, {}.. and your age is {}".format(name,age))


if __name__ == 'main':
   main()
Moderator: icode is for inline code, that's why this wasn't formatted properly.  I've fixed it :)


RE: No option to input - buran - Mar-17-2017

would you like to elaborate further on this assignment, e.g. what getAge and getName are expected to do. This looks like homework, so better say so and provide the full assignment.
in your implementation right now these methods SET new age and name for player. Is that what your intent is? or they are supposed to RETURN the name/age. Also using getters is not necessary in case like this.


RE: No option to input - nilamo - Mar-17-2017

Ok, so you define a class, but never create an instance of it. class player1 should probably be the first couple lines, and then your main() would look a little like:

dan = player1("gibroni", 83)
dan.getName("...gibroni?")
name.player1 and age.player1 are... backwards. name doesn't have a player1, but player1 does have a name.


RE: No option to input - Sp00f - Mar-17-2017

(Mar-17-2017, 08:59 PM)buran Wrote: would you like to elaborate further on this assignment, e.g. what getAge and getName are expected to do. This looks like homework, so better say so and provide the full assignment.
in your implementation right now these methods SET new age and name for player. Is that what your intent is? or they are supposed to RETURN the name/age. Also using getters is not necessary in case like this.

http://www.practicepython.org/exercise/2014/01/29/01-character-input.html

I'm teaching myself python. That exercise interested me and I felt like I was ready to give it a shot.
I got stuck, so I found a forum on python
________________________
nilamo
Ok, so you define a class, but never create an instance of it. class player1 should probably be the first couple lines, and then your main() would look a little like:

dan = player1("gibroni", 83)
    dan.getName("...gibroni?")
name.player1 and age.player1 are... backwards. name doesn't have a player1, but player1 does have a name.
______________________

Thank you, I'll try that.. good info


RE: No option to input - buran - Mar-17-2017

why not keep it as simple as possible? There is no need for using class, or even a function ro complete this task. You already did it ore or less:
name = input('What is your name? ')
age = input('How old are you? ')
print("Cool, {}.. and your age is {}. You will turn 100 in year {}.".format(name,age, 2017 - int(age)+100))
that is, assuming you are using python3


RE: No option to input - Sp00f - Mar-17-2017

(Mar-17-2017, 09:45 PM)buran Wrote: why not keep it as simple as possible? There is no need for using class, or even a function ro complete this task. You already did it ore or less:
name = input('What is your name? ') age = input('How old are you? ') print("Cool, {}.. and your age is {}. You will turn 100 in year {}.".format(name,age, 2017 - int(age)+100))
that is, assuming you are using python3

oh thats how its done?

ty