Mar-17-2017, 08:37 PM
![[Image: Sw4cJfq.png]](https://i.imgur.com/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
No option to input
|
Mar-17-2017, 08:37 PM
![]() 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
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
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 :)
Mar-17-2017, 08:59 PM
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.
Mar-17-2017, 08:59 PM
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 .
(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. http://www.practicepython.org/exercise/2...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
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 (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 |
|