• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 03:24
CET 09:24
KST 17:24
  • 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
Rongyi Cup S3 - RO16 Preview3herO wins SC2 All-Star Invitational10SC2 All-Star Invitational: Tournament Preview5RSL Revival - 2025 Season Finals Preview8RSL Season 3 - Playoffs Preview0
Community News
Weekly Cups (Jan 12-18): herO, MaxPax, Solar win0BSL Season 2025 - Full Overview and Conclusion8Weekly Cups (Jan 5-11): Clem wins big offline, Trigger upsets4$21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7)20Weekly Cups (Dec 29-Jan 4): Protoss rolls, 2v2 returns7
StarCraft 2
General
Oliveira Would Have Returned If EWC Continued StarCraft 2 not at the Esports World Cup 2026 [Short Story] The Last GSL Stellar Fest "01" Jersey Charity Auction PhD study /w SC2 - help with a survey!
Tourneys
$21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7) OSC Season 13 World Championship $70 Prize Pool Ladder Legends Academy Weekly Open! SC2 All-Star Invitational: Jan 17-18 Sparkling Tuna Cup - Weekly Open Tournament
Strategy
Simple Questions Simple Answers
Custom Maps
[A] Starcraft Sound Mod
External Content
Mutation # 509 Doomsday Report Mutation # 508 Violent Night Mutation # 507 Well Trained Mutation # 506 Warp Zone
Brood War
General
[ASL21] Potential Map Candidates Fantasy's Q&A video BGH Auto Balance -> http://bghmmr.eu/ BW General Discussion Gypsy to Korea
Tourneys
[Megathread] Daily Proleagues Azhi's Colosseum - Season 2 Small VOD Thread 2.0 [BSL21] Non-Korean Championship - Starts Jan 10
Strategy
Current Meta Simple Questions, Simple Answers Soma's 9 hatch build from ASL Game 2 Game Theory for Starcraft
Other Games
General Games
Nintendo Switch Thread Battle Aces/David Kim RTS Megathread Stormgate/Frost Giant Megathread Beyond All Reason Awesome Games Done Quick 2026!
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
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
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Canadian Politics Mega-thread NASA and the Private Sector Things Aren’t Peaceful in Palestine
Fan Clubs
The herO Fan Club! The IdrA Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece
Sports
2024 - 2026 Football Thread
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
How Esports Advertising Shap…
TrAiDoS
My 2025 Magic: The Gathering…
DARKING
Life Update and thoughts.
FuDDx
How do archons sleep?
8882
James Bond movies ranking - pa…
Topin
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1614 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
Germany2590 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
Replay Cast
00:00
Rongyi Cup S3 - Group A
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
SortOf 134
FoxeR 72
StarCraft: Brood War
Rain 10038
Sea 3673
Hyuk 822
Jaedong 546
Larva 353
Hm[arnc] 262
Zeus 223
EffOrt 67
Shinee 60
Hyun 54
[ Show more ]
Backho 53
Shuttle 46
Noble 22
NotJumperer 22
Bale 22
ZergMaN 20
Sharp 11
Dota 2
NeuroSwarm159
XcaliburYe126
League of Legends
JimRising 698
Super Smash Bros
Mew2King85
Other Games
WinterStarcraft502
C9.Mang0334
Happy253
XaKoH 170
mouzStarbuck127
RuFF_SC2100
Hui .93
Organizations
Other Games
gamesdonequick1186
StarCraft: Brood War
UltimateBattle 29
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 15 non-featured ]
StarCraft 2
• StrangeGG 88
• Sammyuel 32
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Laughngamez YouTube
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Jankos870
• Stunt513
Upcoming Events
RongYI Cup
2h 36m
SHIN vs Creator
Classic vs Percival
OSC
4h 36m
BSL 21
6h 36m
QiaoGege vs Sziky
Dewalt vs Bonyth
Mihu vs TBD
RongYI Cup
1d 2h
Maru vs Cyan
Solar vs Krystianer
uThermal 2v2 Circuit
1d 3h
BSL 21
1d 6h
Wardi Open
2 days
Monday Night Weeklies
2 days
OSC
2 days
WardiTV Invitational
3 days
[ Show More ]
WardiTV Invitational
4 days
The PondCast
5 days
Korean StarCraft League
6 days
Liquipedia Results

Completed

Escore Tournament S1: W5
OSC Championship Season 13
NA Kuram Kup

Ongoing

C-Race Season 1
BSL 21 Non-Korean Championship
CSL 2025 WINTER (S19)
KCM Race Survival 2026 Season 1
Rongyi Cup S3
Underdog Cup #3
Tektek Cup #1
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025

Upcoming

Acropolis #4 - TS4
Escore Tournament S1: W6
Escore Tournament S1: W7
Acropolis #4
IPSL Spring 2026
uThermal 2v2 2026 Main Event
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
Nations Cup 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League Season 23
ESL Pro League Season 23
PGL Cluj-Napoca 2026
IEM Kraków 2026
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.