• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 04:53
CEST 10:53
KST 17:53
  • 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
Code S Season 1 (2026) - RO4 & Finals Preview4[ASL21] Ro4 Preview: On Course12Code S Season 1 - RO8 Preview7[ASL21] Ro8 Preview Pt2: Progenitors8Code S Season 1 - RO12 Group A: Rogue, Percival, Solar, Zoun13
Community News
Code S Season 1 (2026) - RO8 Results2Weekly Cups (May 4-10): Clem, MaxPax, herO win1Maestros of The Game 2 announcement and schedule !11Weekly Cups (April 27-May 4): Clem takes triple0RSL Revival: Season 5 - Qualifiers and Main Event12
StarCraft 2
General
Code S Season 1 (2026) - RO4 & Finals Preview Code S Season 1 (2026) - RO8 Results Code S Season 1 (2026) - RO12 Results Team Liquid Map Contest #22 - The Finalists MaNa leaves Team Liquid
Tourneys
GSL Code S Season 1 (2026) Sparkling Tuna Cup - Weekly Open Tournament KSL Week 89 2026 GSL Season 2 Qualifiers Maestros of The Game 2 announcement and schedule !
Strategy
Custom Maps
[D]RTS in all its shapes and glory <3 [A] Nemrods 1/4 players
External Content
Mutation # 525 Wheel of Misfortune The PondCast: SC2 News & Results Mutation # 524 Death and Taxes Mutation # 523 Firewall
Brood War
General
Pros React to: TvT Masterclass in FlaSh vs Light vespene.gg — BW replays in browser BGH Auto Balance -> http://bghmmr.eu/ BW General Discussion ASL21 General Discussion
Tourneys
[BSL22] RO8 Bracket Stage + Another TieBreaker [ASL21] Semifinals B [ASL21] Ro8 Day 4 Escore Tournament StarCraft Season 2
Strategy
Muta micro map competition Fighting Spirit mining rates [G] Hydra ZvZ: An Introduction Simple Questions, Simple Answers
Other Games
General Games
Path of Exile Stormgate/Frost Giant Megathread Nintendo Switch Thread Warcraft III: The Frozen Throne Starcraft Tabletop Miniature Game
Dota 2
The Story of Wings Gaming
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 TL Mafia Community Thread Five o'clock TL Mafia
Community
General
US Politics Mega-thread YouTube Thread European Politico-economics QA Mega-thread Russo-Ukrainian War Thread UK Politics Mega-thread
Fan Clubs
The herO Fan Club!
Media & Entertainment
[Manga] One Piece Anime Discussion Thread [Req][Books] Good Fantasy/SciFi books
Sports
2024 - 2026 Football Thread McBoner: A hockey love story Formula 1 Discussion
World Cup 2022
Tech Support
streaming software Strange computer issues (software) [G] How to Block Livestream Ads
TL Community
The Automated Ban List
Blogs
How EEG Data Can Predict Gam…
TrAiDoS
ramps on octagon
StaticNine
Funny Nicknames
LUCKY_NOOB
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1958 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
GSL
08:00
2026 Season 1: Playoffs
Cure vs herOLIVE!
SHIN vs Maru
GSL EN (SOOP)0
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Rex 36
StarCraft: Brood War
Killer 939
Mind 579
Hm[arnc] 270
Larva 217
scan(afreeca) 213
Zeus 176
PianO 62
Backho 36
JulyZerg 29
Sacsri 28
[ Show more ]
Sharp 26
Bale 17
EffOrt 14
Noble 10
Dota 2
XaKoH 502
NeuroSwarm156
League of Legends
JimRising 545
Other Games
summit1g9846
WinterStarcraft515
monkeys_forever270
crisheroes78
Organizations
Counter-Strike
PGL16456
StarCraft 2
IntoTheiNu 340
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 16 non-featured ]
StarCraft 2
• Berry_CruncH251
• CranKy Ducklings SOOP58
• LUISG 40
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Jankos1039
• Lourlo793
Counter-Strike
• C_a_k_e 1796
Upcoming Events
IPSL
7h 7m
Bonyth vs Napoleon
G5 vs JDConan
BSL
10h 7m
OyAji vs JDConan
DragOn vs TBD
Replay Cast
1d
Monday Night Weeklies
1d 7h
Replay Cast
1d 15h
The PondCast
2 days
Kung Fu Cup
2 days
GSL
3 days
Replay Cast
3 days
GSL
4 days
[ Show More ]
WardiTV Spring Champion…
4 days
Replay Cast
4 days
Sparkling Tuna Cup
5 days
WardiTV Spring Champion…
5 days
Replay Cast
5 days
RSL Revival
6 days
Classic vs SHIN
Rogue vs Bunny
BSL
6 days
Replay Cast
6 days
Afreeca Starleague
6 days
Liquipedia Results

Completed

Escore Tournament S2: W7
WardiTV TLMC #16
Nations Cup 2026

Ongoing

BSL Season 22
ASL Season 21
IPSL Spring 2026
KCM Race Survival 2026 Season 2
Acropolis #4
KK 2v2 League Season 1
BSL 22 Non-Korean Championship
SCTL 2026 Spring
RSL Revival: Season 5
2026 GSL S1
Heroes Pulsing #1
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026
BLAST Rivals Spring 2026
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2

Upcoming

YSL S3
Escore Tournament S2: W8
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
Maestros of the Game 2
WardiTV Spring 2026
2026 GSL S2
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
Stake Ranked Episode 3
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 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.