• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 15:39
CET 20:39
KST 04:39
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
[ASL21] Ro24 Preview Pt1: New Chaos0Team Liquid Map Contest #22 - Presented by Monster Energy7ByuL: The Forgotten Master of ZvT30Behind the Blue - Team Liquid History Book19Clem wins HomeStory Cup 289
Community News
Weekly Cups (March 16-22): herO doubles, Cure surprises3Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool48Weekly Cups (March 9-15): herO, Clem, ByuN win42026 KungFu Cup Announcement6BGE Stara Zagora 2026 cancelled12
StarCraft 2
General
Potential Updates Coming to the SC2 CN Server What mix of new & old maps do you want in the next ladder pool? (SC2) Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool Weekly Cups (March 16-22): herO doubles, Cure surprises Weekly Cups (August 25-31): Clem's Last Straw?
Tourneys
WardiTV Mondays Sparkling Tuna Cup - Weekly Open Tournament World University TeamLeague (500$+) | Signups Open RSL Season 4 announced for March-April WardiTV Team League Season 10
Strategy
Custom Maps
[M] (2) Frigid Storage Publishing has been re-enabled! [Feb 24th 2026]
External Content
The PondCast: SC2 News & Results Mutation # 518 Radiation Zone Mutation # 517 Distant Threat Mutation # 516 Specter of Death
Brood War
General
BGH Auto Balance -> http://bghmmr.eu/ Gypsy to Korea Soulkey's decision to leave C9 How much money terran looses from gas steal? mca64Launcher - New Version with StarCraft: Remast
Tourneys
[ASL21] Ro24 Group C [Megathread] Daily Proleagues [ASL21] Ro24 Group B 2026 Changsha Offline Cup
Strategy
What's the deal with APM & what's its true value Fighting Spirit mining rates Simple Questions, Simple Answers Soma's 9 hatch build from ASL Game 2
Other Games
General Games
Darkest Dungeon Nintendo Switch Thread Stormgate/Frost Giant Megathread General RTS Discussion Thread Path of Exile
Dota 2
Official 'what is Dota anymore' discussion The Story of Wings Gaming
League of Legends
G2 just beat GenG in First stand
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Five o'clock TL Mafia Mafia Game Mode Feedback/Ideas Vanilla Mini Mafia
Community
General
US Politics Mega-thread Canadian Politics Mega-thread Russo-Ukrainian War Thread European Politico-economics QA Mega-thread Things Aren’t Peaceful in Palestine
Fan Clubs
The IdrA Fan Club
Media & Entertainment
[Req][Books] Good Fantasy/SciFi books Movie Discussion! [Manga] One Piece
Sports
Cricket [SPORT] 2024 - 2026 Football Thread Formula 1 Discussion Tokyo Olympics 2021 Thread General nutrition recommendations
World Cup 2022
Tech Support
Laptop capable of using Photoshop Lightroom?
TL Community
The Automated Ban List
Blogs
Funny Nicknames
LUCKY_NOOB
Money Laundering In Video Ga…
TrAiDoS
Iranian anarchists: organize…
XenOsky
FS++
Kraekkling
Shocked by a laser…
Spydermine0240
Unintentional protectionism…
Uldridge
ASL S21 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1443 users

The Big Programming Thread - Page 242

Forum Index > General Forum
Post a Reply
Prev 1 240 241 242 243 244 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
Last Edited: 2013-02-12 01:28:05
February 12 2013 01:27 GMT
#4821
On February 12 2013 10:19 darkness wrote:
So I have this little problem to solve:

Show nested quote +
You are in charge of recording marks for a group of students. Input a list of marks. Input ends with 0 (0 itself is not someone's mark). Output the number of students who scored 1) greater than or equal to 85; 2) between 60 and 84; 3) strictly less than 60.


Show nested quote +
Sample Input
88 71 68 70 59 81 91 42 66 77 83 0


I just need a hint how to get input like this in C. Also, how should I go about storing marks? Is this a dynamic memory (heap) matter? I already know about getchar and scanf, but are they enough? Maybe getchar() and putchar()?

Please don't bother to give me the solution. I just need a little help.

Thanks.


This ought to get you on the right track:


char * fgets ( char * str, int num, FILE * stream );.
Any sufficiently advanced technology is indistinguishable from magic
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
February 12 2013 01:28 GMT
#4822
On February 12 2013 10:19 darkness wrote:
So I have this little problem to solve:

Show nested quote +
You are in charge of recording marks for a group of students. Input a list of marks. Input ends with 0 (0 itself is not someone's mark). Output the number of students who scored 1) greater than or equal to 85; 2) between 60 and 84; 3) strictly less than 60.


Show nested quote +
Sample Input
88 71 68 70 59 81 91 42 66 77 83 0


I just need a hint how to get input like this in C. Also, how should I go about storing marks? Is this a dynamic memory (heap) matter? I already know about getchar and scanf, but are they enough? Maybe getchar() and putchar()?

Please don't bother to give me the solution. I just need a little help.

Thanks.

How are you supposed to store these inputs? That's the real question. You can just use scanf -it's perfect for this.
3FFA
Profile Blog Joined February 2010
United States3931 Posts
Last Edited: 2013-02-12 03:49:04
February 12 2013 03:48 GMT
#4823
On February 12 2013 10:28 CecilSunkure wrote:
Show nested quote +
On February 12 2013 10:19 darkness wrote:
So I have this little problem to solve:

You are in charge of recording marks for a group of students. Input a list of marks. Input ends with 0 (0 itself is not someone's mark). Output the number of students who scored 1) greater than or equal to 85; 2) between 60 and 84; 3) strictly less than 60.


Sample Input
88 71 68 70 59 81 91 42 66 77 83 0


I just need a hint how to get input like this in C. Also, how should I go about storing marks? Is this a dynamic memory (heap) matter? I already know about getchar and scanf, but are they enough? Maybe getchar() and putchar()?

Please don't bother to give me the solution. I just need a little help.

Thanks.

How are you supposed to store these inputs? That's the real question. You can just use scanf -it's perfect for this.

I fully agree. Scanf is perfect. And the 0 just requires telling the user to input "0" after a space at the end and telling the program to stop at the "0".

(So glad I can understand things like this now :3)
"As long as it comes from a pure place and from a honest place, you know, you can write whatever you want."
Snuggles
Profile Blog Joined May 2010
United States1865 Posts
Last Edited: 2013-02-12 17:35:47
February 12 2013 17:28 GMT
#4824
Well I just started learning about classes and objects in Python... And it's not going so well. For some reason I just do not understand objects through and through. I feel like there's something fundamentally wrong with my way of thinking about it.

For the past two days I've been tackling a bunch of "simple" problems. We pretty much went from lists to classes/objects and this stuff is just flying over my head compared to previous lessons. I'm about to head down to the remedial hall to get some help tomorrow because if I can't figure this out on my own after two days then this is a problem... Before that I was hoping I could come here and ask for your advice on it. Here's the sort of problem I'm dealing with.

Problem (from myProgrammingLab for those of you who are familiar)
+ Show Spoiler +
Write the definition of a class Player containing:
An instance variable name of type String , initialized to the empty String.
An instance variable score of type int , initialized to zero.
A method called set_name that has one parameter, whose value it assigns to the instance variable name .
A method called set_score that has one parameter, whose value it assigns to the instance variable score .
A method called get_name that has no parameters and that returns the value of the instance variable name .
A method called get_score that has no parameters and that returns the value of the instance variable score .
No constructor need be defined.


Here's my code after dozens of attempts, I even tried a few more while writing this post...
+ Show Spoiler +
class Player :
def __init__ (self, name = "", score = 0):
self.set_name(name)
self.set_score(score)
def set_name(self):
name = self.set_name
def set_score(self):
score = self.set_score
def get_name():
return name
def get_score():
return score


Usually the CodeLab will accept simple answers, and the lines of code they ask for is pretty elementary compared to the brain teasers the book has for its exercises so I am definitely doing something horribly wrong. The Lab keeps telling me I should "use object"... which I don't really understand. I feel like the more time I spend on this, the more confused I get about classes and objects... From my understanding the object in this class would be self, name, and score, but I feel like this should just be done with self, and have self.name = name and self.score = 0.

Or of course I am just a big idiot who just needs someone to correct me, and they could probably do it in a sentences because this is probably very simple ;_; Please help.

Logged 16 attempts today... my professor must be like wtf is this...
Tobberoth
Profile Joined August 2010
Sweden6375 Posts
February 12 2013 17:35 GMT
#4825
On February 13 2013 02:28 Snuggles wrote:
Well I just started learning about classes and objects in Python... And it's not going so well. For some reason I just do not understand objects through and through. I feel like there's something fundamentally wrong with my way of thinking about it.

For the past two days I've been tackling a bunch of "simple" problems. We pretty much went from lists to classes/objects and this stuff is just flying over my head compared to previous lessons. I'm about to head down to the remedial hall to get some help tomorrow because if I can't figure this out on my own after two days then this is a problem... Before that I was hoping I could come here and ask for your advice on it. Here's the sort of problem I'm dealing with.

Problem (from myProgrammingLab for those of you who are familiar)
+ Show Spoiler +
Write the definition of a class Player containing:
An instance variable name of type String , initialized to the empty String.
An instance variable score of type int , initialized to zero.
A method called set_name that has one parameter, whose value it assigns to the instance variable name .
A method called set_score that has one parameter, whose value it assigns to the instance variable score .
A method called get_name that has no parameters and that returns the value of the instance variable name .
A method called get_score that has no parameters and that returns the value of the instance variable score .
No constructor need be defined.


Here's my code after dozens of attempts, I even tried a few more while writing this post...
+ Show Spoiler +
class Player :
def __init__ (self, name = "", score = 0):
self.set_name(name)
self.set_score(score)
def set_name(self):
name = self.set_name
def set_score(self):
score = self.set_score
def get_name():
return name
def get_score():
return score


Usually the CodeLab will accept simple answers, and the lines of code they ask for is pretty elementary compared to the brain teasers the book has for its exercises so I am definitely doing something horribly wrong. The Lab keeps telling me I should "use object"... which I don't really understand. I feel like the more time I spend on this, the more confused I get about classes and objects... From my understanding the object in this class would be self, name, and score, but I feel like this should just be done with self, and have self.name = name and self.score = 0.

Or of course I am just a big idiot who just needs someone to correct me, and they could probably do it in a sentences because this is probably very simple ;_; Please help.

Could is just not be that it wants you to demonstrate the class by using objects of it? I don't know how CodeLab works, but that's what it sounds like... so make a few player objects and use the methods on them.
Snuggles
Profile Blog Joined May 2010
United States1865 Posts
Last Edited: 2013-02-12 17:40:36
February 12 2013 17:40 GMT
#4826
No it wants me to write out the Class, not use it. At some point I remember getting some feedback showing the input, how it runs through my methods.

Here's the problem before that one that I managed to get right.

Problem
+ Show Spoiler +
Write the definition of a class Counter containing:
An instance variable named counter of type int .
A constructor that takes one int argument and assigns its value to counter
A method named increment that adds one to counter . It does not take parameters or return a value.
A method named decrement that subtracts one from counter . It also does not take parameters or return a value.
A method named get_value that returns the value of the instance variable counter .


Answer
+ Show Spoiler +
class Counter:
def __init__(self):
self.counter = 0
def increment(self):
self.counter += 1
def decrement(self):
self.counter -= 1
def get_value (self):
return self.counter


They took that one in real easily. I really don't know where the hell I messed up in the Player problem...
Shenghi
Profile Joined August 2010
167 Posts
Last Edited: 2013-02-12 18:24:11
February 12 2013 18:13 GMT
#4827
On February 13 2013 02:28 Snuggles wrote:
Well I just started learning about classes and objects in Python... And it's not going so well. For some reason I just do not understand objects through and through. I feel like there's something fundamentally wrong with my way of thinking about it.

For the past two days I've been tackling a bunch of "simple" problems. We pretty much went from lists to classes/objects and this stuff is just flying over my head compared to previous lessons. I'm about to head down to the remedial hall to get some help tomorrow because if I can't figure this out on my own after two days then this is a problem... Before that I was hoping I could come here and ask for your advice on it. Here's the sort of problem I'm dealing with.

Problem (from myProgrammingLab for those of you who are familiar)
+ Show Spoiler +
Write the definition of a class Player containing:
An instance variable name of type String , initialized to the empty String.
An instance variable score of type int , initialized to zero.
A method called set_name that has one parameter, whose value it assigns to the instance variable name .
A method called set_score that has one parameter, whose value it assigns to the instance variable score .
A method called get_name that has no parameters and that returns the value of the instance variable name .
A method called get_score that has no parameters and that returns the value of the instance variable score .
No constructor need be defined.


Here's my code after dozens of attempts, I even tried a few more while writing this post...
+ Show Spoiler +
class Player :
def __init__ (self, name = "", score = 0):
self.set_name(name)
self.set_score(score)
def set_name(self):
name = self.set_name
def set_score(self):
score = self.set_score
def get_name():
return name
def get_score():
return score


Usually the CodeLab will accept simple answers, and the lines of code they ask for is pretty elementary compared to the brain teasers the book has for its exercises so I am definitely doing something horribly wrong. The Lab keeps telling me I should "use object"... which I don't really understand. I feel like the more time I spend on this, the more confused I get about classes and objects... From my understanding the object in this class would be self, name, and score, but I feel like this should just be done with self, and have self.name = name and self.score = 0.

Or of course I am just a big idiot who just needs someone to correct me, and they could probably do it in a sentences because this is probably very simple ;_; Please help.

Logged 16 attempts today... my professor must be like wtf is this...

This might be silly, but based on your post before my reply I would try writing the class without constructor. I know that the problem statement doesn't explicitly state that you should not write one, but the Counter problem statement does explicitly state you have to include a constructor, and the Player problem statement hints that they are looking for a solution without constructor.

[Edit]
Just spotted: The line
name = self.set_name
sets a local variable 'name' (local to the method) to point to the method set_name, which is not what you want. What you're looking for is something like this:

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

In your get_xxx methods, you aren't returning an instance variable (self.xxx), but either a local or global variable (depending on which one exists) which Python obviously can't find, because none exists.
People are not born stupid, they choose to be stupid. If you made that choice, please change your mind.
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2013-02-12 19:19:34
February 12 2013 19:18 GMT
#4828
Hey guys, thanks for helping me last time. I have another thing that I struggle with.

Say you have a double variable with this value:

double value = a / b;


let's say 'value = 2.283214570' after division

'a' and 'b' are both integers.

Now, my problem is that I need to print the n-th digit of this double variable. E.g. n = 2

Then output would be '8' because it's the 2nd digit after decimal point. I've thought about double -> string, but my implementation doesn't work for integers that are up to 60000 which is a requirement.

enigmaticcam
Profile Blog Joined October 2010
United States280 Posts
February 12 2013 19:25 GMT
#4829
Anyone here have any experience in .NET with hostname resolution via proxy servers?

Basically, the jackasses in our network team decided it's a security risk for any computer on the network to resolve an internet hostname to an ip address, unless by means of the proxy server. This poses a problem for one of our existing custom apps that handles automatic FTP processes. Since it connects to a remote FTP server by hostname, it no longer works. We've sidestepped the issue temporarily by adding the host names directly to the server's hosts file, but this obviously is not a good solution in the long term.

I did some googling and couldn't really find anything. I need to be able to resolve an internet hostname to an ip address, the caveat being that I have to do it using a proxy server. Any help would really be appreciated. I can work with either VB.NET or C#.NET. Thank you!
WilbertK
Profile Joined May 2010
Netherlands210 Posts
Last Edited: 2013-02-12 20:15:37
February 12 2013 19:44 GMT
#4830
On February 12 2013 08:07 Hitch-22 wrote:
My error is this:

error: CSInfoCore is abstract; cannot be instantiated
arrayCourses[arrCouCompanion] = new CSInfoCore(creditInput, ...)

This follows for the next 4 instantiated sections (one after another).

I can't remove the abstraction, however, because then I get the error (Speaking of classes CSInfoCore through Electives) that you can't edit an abstract method without an abstract class.

THANKS! (This is due tonight, put a lot of time in it, if anyone can put in some good ideas or see where I screwed up that'd be great!)


I would like to help you, but I'm going to need more info. My guess is that you're misusing abstract classes, and that you don't see what consequences that has. It looks like you're using abstract classes to override existing methods. You don't need abstract classes to do that, and by definition you cannot instantiate abstract classes. I think that if I understood what you were trying to accomplish I would be able to help. If you PM me we may be able to get in touch in a more convenient way (google talk or such)

:EDIT: Apparently I confused AM and PM, and this problem is already due. So probably my help comes too late.
supereddie
Profile Joined March 2011
Netherlands151 Posts
February 12 2013 20:32 GMT
#4831
On February 13 2013 04:18 darkness wrote:
Hey guys, thanks for helping me last time. I have another thing that I struggle with.

Say you have a double variable with this value:

Show nested quote +
double value = a / b;


let's say 'value = 2.283214570' after division

'a' and 'b' are both integers.

Now, my problem is that I need to print the n-th digit of this double variable. E.g. n = 2

Then output would be '8' because it's the 2nd digit after decimal point. I've thought about double -> string, but my implementation doesn't work for integers that are up to 60000 which is a requirement.


Just use math?
Multiply 'value' with 10^decimalnumber (so you have 228.3214570). Take the int part of it (=228).
Do it again with decimalnumber - 1 and take int part: 22. Multiply by 10 = 220.
Then just substract the two: 228 - 220 = 8

Something like

double value = a / b; // 2.283214570
double x = Math.Truncate(value * Math.Pow(10, decimalnumber)); // 228
double y = Math.Truncate(value * Math.Pow(10, decimalnumber - 1)) * 10; // 220
double digit = x - y; // 228 - 220 = 8;

Be careful about overflows etc.
"Do not try to make difficult things possible, but make simple things simple." - David Platt on Software Design
DeltaX
Profile Joined August 2011
United States287 Posts
February 12 2013 20:52 GMT
#4832
On February 13 2013 04:18 darkness wrote:
Hey guys, thanks for helping me last time. I have another thing that I struggle with.

Say you have a double variable with this value:

Show nested quote +
double value = a / b;


let's say 'value = 2.283214570' after division

'a' and 'b' are both integers.

Now, my problem is that I need to print the n-th digit of this double variable. E.g. n = 2

Then output would be '8' because it's the 2nd digit after decimal point. I've thought about double -> string, but my implementation doesn't work for integers that are up to 60000 which is a requirement.




Make sure when you calculate "value" that you are actually getting decimals. If your A and B are ints, then there is a good chance you are doing integer division which will never have any decimal places.
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2013-02-12 22:48:57
February 12 2013 22:43 GMT
#4833
On February 13 2013 05:32 supereddie wrote:
Show nested quote +
On February 13 2013 04:18 darkness wrote:
Hey guys, thanks for helping me last time. I have another thing that I struggle with.

Say you have a double variable with this value:

double value = a / b;


let's say 'value = 2.283214570' after division

'a' and 'b' are both integers.

Now, my problem is that I need to print the n-th digit of this double variable. E.g. n = 2

Then output would be '8' because it's the 2nd digit after decimal point. I've thought about double -> string, but my implementation doesn't work for integers that are up to 60000 which is a requirement.


Just use math?
Multiply 'value' with 10^decimalnumber (so you have 228.3214570). Take the int part of it (=228).
Do it again with decimalnumber - 1 and take int part: 22. Multiply by 10 = 220.
Then just substract the two: 228 - 220 = 8

Something like

double value = a / b; // 2.283214570
double x = Math.Truncate(value * Math.Pow(10, decimalnumber)); // 228
double y = Math.Truncate(value * Math.Pow(10, decimalnumber - 1)) * 10; // 220
double digit = x - y; // 228 - 220 = 8;

Be careful about overflows etc.


Awesome. This code only needs slight modification to make it work though.

Math.Truncate = trunc in C
Math.Pow = pow in C

But yeah, this is irrelevant.

Thanks.

Edit: Actually, it seems I've forgotten to say it's for C, but yeah... it's obvious how to fix this.

Edit 2: You may also want to change 'digit' to: int digit = (int)x - (int)y; because it's more natural for this scenario.
AmericanUmlaut
Profile Blog Joined November 2010
Germany2594 Posts
Last Edited: 2013-02-13 08:15:52
February 13 2013 04:10 GMT
#4834
On February 13 2013 07:43 darkness wrote:
Show nested quote +
On February 13 2013 05:32 supereddie wrote:
On February 13 2013 04:18 darkness wrote:
Hey guys, thanks for helping me last time. I have another thing that I struggle with.

Say you have a double variable with this value:

double value = a / b;


let's say 'value = 2.283214570' after division

'a' and 'b' are both integers.

Now, my problem is that I need to print the n-th digit of this double variable. E.g. n = 2

Then output would be '8' because it's the 2nd digit after decimal point. I've thought about double -> string, but my implementation doesn't work for integers that are up to 60000 which is a requirement.


Just use math?
Multiply 'value' with 10^decimalnumber (so you have 228.3214570). Take the int part of it (=228).
Do it again with decimalnumber - 1 and take int part: 22. Multiply by 10 = 220.
Then just substract the two: 228 - 220 = 8

Something like

double value = a / b; // 2.283214570
double x = Math.Truncate(value * Math.Pow(10, decimalnumber)); // 228
double y = Math.Truncate(value * Math.Pow(10, decimalnumber - 1)) * 10; // 220
double digit = x - y; // 228 - 220 = 8;

Be careful about overflows etc.


Awesome. This code only needs slight modification to make it work though.

Math.Truncate = trunc in C
Math.Pow = pow in C

But yeah, this is irrelevant.

Thanks.

Edit: Actually, it seems I've forgotten to say it's for C, but yeah... it's obvious how to fix this.

Edit 2: You may also want to change 'digit' to: int digit = (int)x - (int)y; because it's more natural for this scenario.

That's a lot more complicated than it needs to be:


int(value * pow(10, decimalnumber)) % 10


2.283214570 * 100 => 228.3214570
cast to int => 228
228 mod 10 => 8

Edit: Forgot to include "value" in the above :-/
The frumious Bandersnatch
Snuggles
Profile Blog Joined May 2010
United States1865 Posts
February 13 2013 05:30 GMT
#4835
On February 13 2013 03:13 Shenghi wrote:
Show nested quote +
On February 13 2013 02:28 Snuggles wrote:
Well I just started learning about classes and objects in Python... And it's not going so well. For some reason I just do not understand objects through and through. I feel like there's something fundamentally wrong with my way of thinking about it.

For the past two days I've been tackling a bunch of "simple" problems. We pretty much went from lists to classes/objects and this stuff is just flying over my head compared to previous lessons. I'm about to head down to the remedial hall to get some help tomorrow because if I can't figure this out on my own after two days then this is a problem... Before that I was hoping I could come here and ask for your advice on it. Here's the sort of problem I'm dealing with.

Problem (from myProgrammingLab for those of you who are familiar)
+ Show Spoiler +
Write the definition of a class Player containing:
An instance variable name of type String , initialized to the empty String.
An instance variable score of type int , initialized to zero.
A method called set_name that has one parameter, whose value it assigns to the instance variable name .
A method called set_score that has one parameter, whose value it assigns to the instance variable score .
A method called get_name that has no parameters and that returns the value of the instance variable name .
A method called get_score that has no parameters and that returns the value of the instance variable score .
No constructor need be defined.


Here's my code after dozens of attempts, I even tried a few more while writing this post...
+ Show Spoiler +
class Player :
def __init__ (self, name = "", score = 0):
self.set_name(name)
self.set_score(score)
def set_name(self):
name = self.set_name
def set_score(self):
score = self.set_score
def get_name():
return name
def get_score():
return score


Usually the CodeLab will accept simple answers, and the lines of code they ask for is pretty elementary compared to the brain teasers the book has for its exercises so I am definitely doing something horribly wrong. The Lab keeps telling me I should "use object"... which I don't really understand. I feel like the more time I spend on this, the more confused I get about classes and objects... From my understanding the object in this class would be self, name, and score, but I feel like this should just be done with self, and have self.name = name and self.score = 0.

Or of course I am just a big idiot who just needs someone to correct me, and they could probably do it in a sentences because this is probably very simple ;_; Please help.

Logged 16 attempts today... my professor must be like wtf is this...

This might be silly, but based on your post before my reply I would try writing the class without constructor. I know that the problem statement doesn't explicitly state that you should not write one, but the Counter problem statement does explicitly state you have to include a constructor, and the Player problem statement hints that they are looking for a solution without constructor.

[Edit]
Just spotted: The line
name = self.set_name
sets a local variable 'name' (local to the method) to point to the method set_name, which is not what you want. What you're looking for is something like this:

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

In your get_xxx methods, you aren't returning an instance variable (self.xxx), but either a local or global variable (depending on which one exists) which Python obviously can't find, because none exists.


Thanks for catching those, that helped for the other problems I did. I still can't get the correct code for that one problem though. But I'm just gonna go to the extra help session. I flew through the exercises (which are ridiculously harder) and the rest of the Code Lab without a problem, so that's a good sign that I just don't get what the CodeLab wants from me on that one question =_=. All that meddling with classes and objects was really good practice, I have a real good idea of how they work now. Still I can only imagine how much more complicated it could get.
waxypants
Profile Blog Joined September 2009
United States479 Posts
February 13 2013 13:56 GMT
#4836
On February 13 2013 02:40 Snuggles wrote:
No it wants me to write out the Class, not use it. At some point I remember getting some feedback showing the input, how it runs through my methods.

Here's the problem before that one that I managed to get right.

Problem
+ Show Spoiler +
Write the definition of a class Counter containing:
An instance variable named counter of type int .
A constructor that takes one int argument and assigns its value to counter
A method named increment that adds one to counter . It does not take parameters or return a value.
A method named decrement that subtracts one from counter . It also does not take parameters or return a value.
A method named get_value that returns the value of the instance variable counter .


Answer
+ Show Spoiler +
class Counter:
def __init__(self):
self.counter = 0
def increment(self):
self.counter += 1
def decrement(self):
self.counter -= 1
def get_value (self):
return self.counter


They took that one in real easily. I really don't know where the hell I messed up in the Player problem...


Actually the __init__ should be something like:


def __init__(self, counter):
self.counter = counter
waxypants
Profile Blog Joined September 2009
United States479 Posts
February 13 2013 13:58 GMT
#4837
On February 12 2013 10:28 CecilSunkure wrote:
Show nested quote +
On February 12 2013 10:19 darkness wrote:
So I have this little problem to solve:

You are in charge of recording marks for a group of students. Input a list of marks. Input ends with 0 (0 itself is not someone's mark). Output the number of students who scored 1) greater than or equal to 85; 2) between 60 and 84; 3) strictly less than 60.


Sample Input
88 71 68 70 59 81 91 42 66 77 83 0


I just need a hint how to get input like this in C. Also, how should I go about storing marks? Is this a dynamic memory (heap) matter? I already know about getchar and scanf, but are they enough? Maybe getchar() and putchar()?

Please don't bother to give me the solution. I just need a little help.

Thanks.

How are you supposed to store these inputs? That's the real question. You can just use scanf -it's perfect for this.


There's no need to really store the list of inputs. You just need to read one at a time and update the appropriate category.
alwinuz
Profile Joined September 2011
Netherlands77 Posts
February 13 2013 14:19 GMT
#4838
On February 13 2013 04:25 enigmaticcam wrote:
Anyone here have any experience in .NET with hostname resolution via proxy servers?

Basically, the jackasses in our network team decided it's a security risk for any computer on the network to resolve an internet hostname to an ip address, unless by means of the proxy server. This poses a problem for one of our existing custom apps that handles automatic FTP processes. Since it connects to a remote FTP server by hostname, it no longer works. We've sidestepped the issue temporarily by adding the host names directly to the server's hosts file, but this obviously is not a good solution in the long term.

I did some googling and couldn't really find anything. I need to be able to resolve an internet hostname to an ip address, the caveat being that I have to do it using a proxy server. Any help would really be appreciated. I can work with either VB.NET or C#.NET. Thank you!


If you want to use a proxy server, you can assign the default proxy to your web request or something simililar. Maybe it is also possible to set the proxy for your code that makes the FTP connection.

We had a similar problem where we could not connect to a old asmx webservice because we didn't use the system proxy.
Now we have this code in the client to connect to the webservice (ws variable):
// Make sure that webservice calls can pass through intranet proxy
ws.Credentials = CredentialCache.DefaultCredentials;
ws.Proxy = WebRequest.DefaultWebProxy;
if (ws.Proxy != null) ws.Proxy.Credentials = CredentialCache.DefaultCredentials;


I hope this helps, not sure if I understood your question correctly.
Else you can maybe try to start up ping.exe with Process.Start() and parse the output?
uZr
Profile Joined April 2011
20 Posts
Last Edited: 2013-02-13 14:37:58
February 13 2013 14:36 GMT
#4839
On February 13 2013 04:25 enigmaticcam wrote:
Anyone here have any experience in .NET with hostname resolution via proxy servers?

Basically, the jackasses in our network team decided it's a security risk for any computer on the network to resolve an internet hostname to an ip address, unless by means of the proxy server. This poses a problem for one of our existing custom apps that handles automatic FTP processes. Since it connects to a remote FTP server by hostname, it no longer works. We've sidestepped the issue temporarily by adding the host names directly to the server's hosts file, but this obviously is not a good solution in the long term.

I did some googling and couldn't really find anything. I need to be able to resolve an internet hostname to an ip address, the caveat being that I have to do it using a proxy server. Any help would really be appreciated. I can work with either VB.NET or C#.NET. Thank you!

Setup your local DHCP server to advertise your proxy as the DNS server ? I guess this would be the best (thus thats in the hand of your network team) especially since that's a way of enforcing the fact that name resolution should go through your proxy.
If instead they want the traffic to go through that proxy to another dns server then what's hinted above should help.
supereddie
Profile Joined March 2011
Netherlands151 Posts
February 13 2013 17:56 GMT
#4840
On February 13 2013 13:10 AmericanUmlaut wrote:
Show nested quote +
On February 13 2013 07:43 darkness wrote:
On February 13 2013 05:32 supereddie wrote:
On February 13 2013 04:18 darkness wrote:
Hey guys, thanks for helping me last time. I have another thing that I struggle with.

Say you have a double variable with this value:

double value = a / b;


let's say 'value = 2.283214570' after division

'a' and 'b' are both integers.

Now, my problem is that I need to print the n-th digit of this double variable. E.g. n = 2

Then output would be '8' because it's the 2nd digit after decimal point. I've thought about double -> string, but my implementation doesn't work for integers that are up to 60000 which is a requirement.


Just use math?
Multiply 'value' with 10^decimalnumber (so you have 228.3214570). Take the int part of it (=228).
Do it again with decimalnumber - 1 and take int part: 22. Multiply by 10 = 220.
Then just substract the two: 228 - 220 = 8

Something like

double value = a / b; // 2.283214570
double x = Math.Truncate(value * Math.Pow(10, decimalnumber)); // 228
double y = Math.Truncate(value * Math.Pow(10, decimalnumber - 1)) * 10; // 220
double digit = x - y; // 228 - 220 = 8;

Be careful about overflows etc.


Awesome. This code only needs slight modification to make it work though.

Math.Truncate = trunc in C
Math.Pow = pow in C

But yeah, this is irrelevant.

Thanks.

Edit: Actually, it seems I've forgotten to say it's for C, but yeah... it's obvious how to fix this.

Edit 2: You may also want to change 'digit' to: int digit = (int)x - (int)y; because it's more natural for this scenario.

That's a lot more complicated than it needs to be:


int(value * pow(10, decimalnumber)) % 10


2.283214570 * 100 => 228.3214570
cast to int => 228
228 mod 10 => 8

Edit: Forgot to include "value" in the above :-/

Doh, ofcourse! How could I forget about the mod operator
"Do not try to make difficult things possible, but make simple things simple." - David Platt on Software Design
Prev 1 240 241 242 243 244 1032 Next
Please log in or register to reply.
Live Events Refresh
OSC
18:00
OSC Elite Rising Star #18
SteadfastSC156
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
elazer 256
SteadfastSC 156
SpeCial 125
UpATreeSC 105
mouzHeroMarine 100
JuggernautJason67
MindelVK 33
StarCraft: Brood War
Britney 14183
Calm 2751
EffOrt 541
Horang2 405
Shuttle 345
ggaemo 75
Backho 57
HiyA 42
soO 20
ivOry 5
Dota 2
Gorgc8695
Counter-Strike
fl0m1554
Other Games
summit1g5003
tarik_tv2627
Grubby2262
B2W.Neo922
Beastyqt633
ArmadaUGS139
C9.Mang0107
QueenE69
mouzStarbuck65
Trikslyr52
Mew2King40
Organizations
Other Games
gamesdonequick1817
BasetradeTV24
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 20 non-featured ]
StarCraft 2
• Kozan
• sooper7s
• Migwel
• LaughNgamezSOOP
• AfreecaTV YouTube
• IndyKCrew
• intothetv
StarCraft: Brood War
• RayReign 12
• 80smullet 9
• ZZZeroYoutube
• STPLYoutube
• BSLYoutube
Dota 2
• C_a_k_e 1576
• WagamamaTV541
League of Legends
• Nemesis4305
• Jankos1733
• TFBlade690
Other Games
• Scarra1320
• imaqtpie974
• Shiphtur140
Upcoming Events
Replay Cast
4h 21m
WardiTV Team League
16h 21m
Big Brain Bouts
21h 21m
Fjant vs SortOf
YoungYakov vs Krystianer
Reynor vs HeRoMaRinE
RSL Revival
1d 14h
Cure vs Zoun
herO vs Rogue
WardiTV Team League
1d 16h
Platinum Heroes Events
1d 19h
BSL
2 days
RSL Revival
2 days
ByuN vs Maru
MaxPax vs TriGGeR
WardiTV Team League
2 days
BSL
2 days
[ Show More ]
Replay Cast
3 days
Replay Cast
3 days
Afreeca Starleague
3 days
Light vs Calm
Royal vs Mind
Wardi Open
3 days
Monday Night Weeklies
3 days
OSC
4 days
Sparkling Tuna Cup
4 days
Afreeca Starleague
4 days
Rush vs PianO
Flash vs Speed
Replay Cast
5 days
Afreeca Starleague
5 days
BeSt vs Leta
Queen vs Jaedong
Replay Cast
6 days
The PondCast
6 days
Liquipedia Results

Completed

Proleague 2026-03-25
WardiTV Winter 2026
Underdog Cup #3

Ongoing

KCM Race Survival 2026 Season 1
BSL Season 22
CSL Elite League 2026
CSL Season 20: Qualifier 1
ASL Season 21
Acropolis #4 - TS6
RSL Revival: Season 4
Nations Cup 2026
NationLESS Cup
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual

Upcoming

2026 Changsha Offline CUP
CSL Season 20: Qualifier 2
CSL 2026 SPRING (S20)
Acropolis #4
IPSL Spring 2026
BSL 22 Non-Korean Championship
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
IEM Atlanta 2026
Asian Champions League 2026
PGL Astana 2026
BLAST Rivals Spring 2026
CCT Season 3 Global Finals
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.