• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 16:21
CET 22:21
KST 06:21
  • 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
RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10
Community News
Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2BGE Stara Zagora 2026 announced15[BSL21] Ro.16 Group Stage (C->B->A->D)4Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win3RSL Season 3: RO16 results & RO8 bracket13
StarCraft 2
General
Chinese SC2 server to reopen; live all-star event in Hangzhou Maestros of the Game: Live Finals Preview (RO4) BGE Stara Zagora 2026 announced Weekly Cups (Nov 24-30): MaxPax, Clem, herO win SC2 Proleague Discontinued; SKT, KT, SGK, CJ disband
Tourneys
Sparkling Tuna Cup - Weekly Open Tournament RSL Offline Finals Info - Dec 13 and 14! StarCraft Evolution League (SC Evo Biweekly) RSL Offline FInals Sea Duckling Open (Global, Bronze-Diamond)
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 502 Negative Reinforcement Mutation # 501 Price of Progress Mutation # 500 Fright night Mutation # 499 Chilling Adaptation
Brood War
General
BW General Discussion [ASL20] Ask the mapmakers — Drop your questions Which season is the best in ASL? Data analysis on 70 million replays BGH Auto Balance -> http://bghmmr.eu/
Tourneys
[Megathread] Daily Proleagues [BSL21] RO16 Group D - Sunday 21:00 CET [BSL21] RO16 Group A - Saturday 21:00 CET [BSL21] RO16 Group B - Sunday 21:00 CET
Strategy
Current Meta Game Theory for Starcraft How to stay on top of macro? PvZ map balance
Other Games
General Games
Path of Exile Nintendo Switch Thread Stormgate/Frost Giant Megathread ZeroSpace Megathread The Perfect Game
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
Mafia Game Mode Feedback/Ideas TL Mafia Community Thread
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine The Big Programming Thread Artificial Intelligence Thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
[Manga] One Piece Movie Discussion! Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Where to ask questions and add stream? The Automated Ban List
Blogs
I decided to write a webnov…
DjKniteX
Physical Exertion During Gam…
TrAiDoS
James Bond movies ranking - pa…
Topin
Thanks for the RSL
Hildegard
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1418 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
Germany2581 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
Next event in 2h 39m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Railgan 99
StarCraft: Brood War
Britney 13948
Calm 2650
Shuttle 542
Larva 202
firebathero 112
ZZZero.O 24
Dota 2
capcasts96
Counter-Strike
fl0m5498
Heroes of the Storm
Liquid`Hasu431
Khaldor128
Other Games
Grubby4225
tarik_tv3792
RotterdaM180
C9.Mang0149
Trikslyr69
XaKoH 54
Mew2King38
ViBE28
Chillindude8
Organizations
Other Games
Algost 8
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 18 non-featured ]
StarCraft 2
• musti20045 17
• Dystopia_ 5
• LaughNgamezSOOP
• sooper7s
• AfreecaTV YouTube
• intothetv
• Migwel
• Kozan
• IndyKCrew
StarCraft: Brood War
• 80smullet 24
• FirePhoenix10
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• WagamamaTV747
League of Legends
• TFBlade1120
Other Games
• imaqtpie1462
• Shiphtur180
Upcoming Events
Replay Cast
2h 39m
Korean StarCraft League
1d 5h
CranKy Ducklings
1d 12h
WardiTV 2025
1d 14h
SC Evo League
1d 15h
BSL 21
1d 22h
Sziky vs OyAji
Gypsy vs eOnzErG
OSC
2 days
Solar vs Creator
ByuN vs Gerald
Percival vs Babymarine
Moja vs Krystianer
EnDerr vs ForJumy
sebesdes vs Nicoract
Sparkling Tuna Cup
2 days
WardiTV 2025
2 days
OSC
2 days
[ Show More ]
BSL 21
2 days
Bonyth vs StRyKeR
Tarson vs Dandy
Replay Cast
3 days
Wardi Open
3 days
StarCraft2.fi
3 days
Monday Night Weeklies
3 days
Replay Cast
4 days
WardiTV 2025
4 days
StarCraft2.fi
4 days
PiGosaur Monday
5 days
StarCraft2.fi
5 days
Tenacious Turtle Tussle
6 days
The PondCast
6 days
WardiTV 2025
6 days
StarCraft2.fi
6 days
Liquipedia Results

Completed

Proleague 2025-11-30
RSL Revival: Season 3
Light HT

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
YSL S2
BSL Season 21
CSCL: Masked Kings S3
Slon Tour Season 2
Acropolis #4 - TS3
META Madness #9
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
Kuram Kup
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
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 © 2025 TLnet. All Rights Reserved.